From c6a32c6d164bda8a7771aec283e8bbada04d56f6 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Mon, 27 Nov 2023 18:04:14 -0800 Subject: [PATCH 1/6] chore: add test fixtures --- ...dd6tnmatjdephcskwsfxfkaqvdobi7c24ni2u.raw.bin | Bin 0 -> 1488 bytes ...jpefk3s43erwzibujnr7rcd4rxxt2pd2y5vma.raw.bin | Bin 0 -> 1167 bytes ...4ce6defcxesn25yr2qjxevcqy2stsns5kj2xi.raw.bin | Bin 0 -> 1255 bytes ...owpjhpuiobmvvemmjnuvibqlhyxfxkl6tgjcy.raw.bin | Bin 0 -> 1488 bytes ...n3fokjfnqyqr6kl2ebh2sngfnwzfa5yos2ife.raw.bin | Bin 0 -> 1488 bytes ...nyeadv5pejntop4xokrlrudvmnwu5t4gicaku.raw.bin | Bin 0 -> 1488 bytes ...3qkxzmdszs4ydlmjfn7teesksta5t3oeeprua.raw.bin | Bin 0 -> 1488 bytes ...elmcapwvbpcthepfkwq2vwonmlhirbjmotedi.raw.bin | Bin 0 -> 286 bytes ...qmkhv64fhwccoljjeuqej5ogb5gzjlylmonf4.raw.bin | Bin 0 -> 1488 bytes 9 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/fixtures/bafyreia7ztv2rhv363az3dd6tnmatjdephcskwsfxfkaqvdobi7c24ni2u.raw.bin create mode 100644 test/fixtures/bafyreibkcamxzxibhtvwgjpefk3s43erwzibujnr7rcd4rxxt2pd2y5vma.raw.bin create mode 100644 test/fixtures/bafyreibwa2zmkzcz4kib74ce6defcxesn25yr2qjxevcqy2stsns5kj2xi.raw.bin create mode 100644 test/fixtures/bafyreice5yg453vvbaso4owpjhpuiobmvvemmjnuvibqlhyxfxkl6tgjcy.raw.bin create mode 100644 test/fixtures/bafyreicm6erjl6zqlsaf3n3fokjfnqyqr6kl2ebh2sngfnwzfa5yos2ife.raw.bin create mode 100644 test/fixtures/bafyreicw73odv37k2pimrnyeadv5pejntop4xokrlrudvmnwu5t4gicaku.raw.bin create mode 100644 test/fixtures/bafyreicyir4fzeucvnesg3qkxzmdszs4ydlmjfn7teesksta5t3oeeprua.raw.bin create mode 100644 test/fixtures/bafyreif3tfdpr5n4jdrbielmcapwvbpcthepfkwq2vwonmlhirbjmotedi.raw.bin create mode 100644 test/fixtures/bafyreif446gqrox2ji4qyqmkhv64fhwccoljjeuqej5ogb5gzjlylmonf4.raw.bin diff --git a/test/fixtures/bafyreia7ztv2rhv363az3dd6tnmatjdephcskwsfxfkaqvdobi7c24ni2u.raw.bin b/test/fixtures/bafyreia7ztv2rhv363az3dd6tnmatjdephcskwsfxfkaqvdobi7c24ni2u.raw.bin new file mode 100644 index 0000000000000000000000000000000000000000..8ddb6bd6f7890c4fa10d849a434897acd3fdefb9 GIT binary patch literal 1488 zcmYMwe>~H99KdmtR7&}^*wFd$7^j-4P|^G-89TcCI1Ov^tL#|$wZ{@>Gb$?DX*ITy zmFbi@$~4z?$XKxq`H_ZnwPnfDoSt!LaCX&uZLerH;Q23S5QqT`g)o-9lWKfHw*E>Q} z!zE}>;sm8_5lUw+l->X+3O*F&0+ewdC@K>ub0?u_{yTl&4doLP%I8ifI#n2wzB~s* zGGIqw$!X-{sn9#eHxp2LunaRhWTF|~b5r=ADOnX%vn=fn(Yr$$Wnuz>ge_f`<-Pg} z;PX|UOPtD^?11stWx9t1sfZgzlSiTViZXXh61*p#0Ju9Z_5STl1!gQi7dC{Nxs`nu z_p*D9Fnil|=ZH<*nDqdPKM&~a@TZeV`>-uPYZ8oDClI2dcy*b80v}ADIKcu?kX@%* z6F_^6AX!^1avwGFh%+`W--Kw-D{&q`k?`!Qi`bWoe(vYuw<9^v{b~54feiu^ zgU9NSjwVeGfDtjF#=1GytTe#WY6mdlpx;oH=jjaKixpGk55wWK$vq<7uCi|andXC*%hiD+Q*-O4@dIt60Gjut zhw-|J@%Pjga(3}7UmCGG`o{tp8Cw<-DRHWX1L(a{L+>MW?A_xN8%K#;zvQ|ivVZ3C z-Vx7MVlXA-OCx}Io*Z|dvGIaW|N19IVIr&B&*8=mLPgu{pPlVn0OulLC`D z#BSz?_tdA*K(-+;(!i!9ZH+-_`&M)- zfHu!a^G>HY4&~D=1a!v3CjD!(24dCw#RIAFc*(K!Isg&2b+cCQZTlJ41nciMd3DX# znunRYHCIwvsfsUMBou%_X=iHn2h|VI;f5EM_m7?G;wD;zGHr?*9ou+8xB?A;OqY|W z{6bOT7Q6i2hVrGjc;%H{l8g`198Lv3opBxmU{&9idPJRgWvL>epv(RaQDd9<&Q*r3 zuzD-OJrnSI0DKyWuD<8j7iZd%mkA%UdGUIP2~Sci+F}c&QR30UHUJq}fsW1FmDd#Q zC}W8wW@?Z4j|?XfQ(xX9*J_I!+yRVQR(Z|88CJ^M4D>W(Y&5T?PZ~x{@oJXTAA4Zu o_Y;6-7ab{yi|c03kToW`U!xe~mnV<+7CN)1BYSoV-TN5-0?_w?R{#J2 literal 0 HcmV?d00001 diff --git a/test/fixtures/bafyreibkcamxzxibhtvwgjpefk3s43erwzibujnr7rcd4rxxt2pd2y5vma.raw.bin b/test/fixtures/bafyreibkcamxzxibhtvwgjpefk3s43erwzibujnr7rcd4rxxt2pd2y5vma.raw.bin new file mode 100644 index 0000000000000000000000000000000000000000..4f0d640dc3f1e6dc68b4c6d1e253b384b2aa3c90 GIT binary patch literal 1167 zcmZ3Ol9E`GI74Aka&BgxloK0&BUqq4IW*WYDKt1K*d^UJGbbrAFFV!L+{o1Ew}ad4 z^aVdTbABI)&=5%Sz4QsLb3a%o1Dt;l!=#|pvdo;Ee6UHDK$E)qV>G@V2AZVYkve6) zKV0X3RFec4QA|omNcipG^g!Xr?4^%^dP{&*@DG??c{IHWsCtva9Mc_(Gm=V+@=}cq z3{8NpaBgF`xLrK*_krN}L}3TNr7)B9(M)ncH3_dP;?eXbpz2NXbjXlCW0ndR%B?VXrcoLH>joLN$t zYGz_+VFC=HUR5`)Wj;WcE%~+P<_kNR%kt4oD?l?XBqA-ipeQphJ=NUY*uwa?gPrhU zU=aHQ4Z3wj$7bGJm_g-e234RL$w|yBNlZ01Fg7s#?cnfg zGboe(J`gJ5%V;%eF)W1UqnWe-%_M)1Oy```vQ(g9DXAtVhDHX!bh+0ku}1pV?*kzz z$LvLf*kEQYM>A^$hFMu2iFx^DsYNCEc|gNVjDRV?CF$eJ-_LV_hFR_W8oBub%&?VE F!vMqL)*1i+ literal 0 HcmV?d00001 diff --git a/test/fixtures/bafyreibwa2zmkzcz4kib74ce6defcxesn25yr2qjxevcqy2stsns5kj2xi.raw.bin b/test/fixtures/bafyreibwa2zmkzcz4kib74ce6defcxesn25yr2qjxevcqy2stsns5kj2xi.raw.bin new file mode 100644 index 0000000000000000000000000000000000000000..bca75dce01afe62f0e1c3add36996e924e8be89e GIT binary patch literal 1255 zcmZ3Ol9E`GI74Aka&BgxRNen~j9`KGRIkK>#JnW0fFwiX6t~ip#0*0VBV7XnBa`0_ zj+gb{gk8Px+aa-V(VX&G*)YBD|AX~1!1y09%`(Y|%+JoxNX$*lFfumOHLx%-1e&*f z!B5WYT|o0n_T67%{|u)8Gn#o{FwHZ{@J!Cg%uXx^nr9AnAIQ8rd$Q_&-Ugai`)8-} zqB$`0zM`4;4bwd1)R6q_%KQvN1CU`BMnJ=ESpBY>$N)5~On9Z1K`6|y?`Veoz% ze5&5`@91v_;hAFX+DtqUM*;Og9g!Rw?3ff9oaF47;hLl1oS2oLmuhKbU}*Wn+a literal 0 HcmV?d00001 diff --git a/test/fixtures/bafyreice5yg453vvbaso4owpjhpuiobmvvemmjnuvibqlhyxfxkl6tgjcy.raw.bin b/test/fixtures/bafyreice5yg453vvbaso4owpjhpuiobmvvemmjnuvibqlhyxfxkl6tgjcy.raw.bin new file mode 100644 index 0000000000000000000000000000000000000000..a1fff623a78df6c28ab903f35de271f71ed08b92 GIT binary patch literal 1488 zcmYMydpOg390%}z-D^!_vd*&RUy$-TKsiGfK%XB0-S&; z1GvfY0kAJ%J^!@Fu-9@X#yN(2P43d zlrIC0!q@X8>mdO9VK7ZbpC$>$VKI>f;gMI+Kh5x1{zT zv9bjLG2u9JhMgLOewJ%2`R3tWu#eGQ@c!dBz!y1_kvsqoafI1_2H|MEJ-vMer{~juI5YBv&=D*w!NQzcP^6(jpM{w#n@;NKI!ypYb|Un@BeHm>)2Hi z=W%#K%=f_;%6Z4mU+Tf3u*t@#-nl0_0qP%P-y zcuh>PYQp9lc$x6)g1aG{8Codp2(j3@6mz%SEzgbi;Ez#^0pcg2uFjK!o^~IHu;Qvz zewMsm{gAR(7hO({SV3zTH+q+?D;FxEOHr6A2zMuHcc@c!isuro|FI(GrQWGm;ANRS znN>WTWaaYg=p2N$W4rlc2HD>;w(d8Xp+A75nBmD)YSc^tSRE0n6rYl!-WP@KGow=YkBkKPT7;5 zxqHGORAG?qudL~`SPd85!S0J-InD~pvWLEKlP4IF_G5dJAXJPDWn<-Z(a+N}M6GDG zdslB~f4^oc_GonptLmG-_VX#ydX_4+8dJ}PJI7_)Rjf);#N2wXjr5(Y(xWNC$&pgn zIG|>+px0tADyp!?#@T23j?PRUsns^K(+lL934_Wd5bE#WKlPN;#V-iDqL>r#{mh%R S7dWXN{rwRBU0YzD4(@;b{djZ$ literal 0 HcmV?d00001 diff --git a/test/fixtures/bafyreicm6erjl6zqlsaf3n3fokjfnqyqr6kl2ebh2sngfnwzfa5yos2ife.raw.bin b/test/fixtures/bafyreicm6erjl6zqlsaf3n3fokjfnqyqr6kl2ebh2sngfnwzfa5yos2ife.raw.bin new file mode 100644 index 0000000000000000000000000000000000000000..63742208af14f490feded891d9a16ec40d605121 GIT binary patch literal 1488 zcmYM!X;hL~7{GD2Oi^4~TnKQBoHR6TbIl^LvMCd^V60>`L(LQ{odFR8L~*CAv>G6z zWXyA%)TG17$~3cGp-gLBFdZv1GtFJ5dEYO0zWmR*&;8wd?x%b8=!t~nljV*mg8nXj zC;~X=;V7XPT0t>3fMd#oVhQI4v|OqO=MnDvT!#@qc&xa z?CGx(rk~plppr)1l7YWD8YR6@vnbL{t#epEKXG7h#LE+xS#r#sM*yxi3X%wJ1>hCu za27JM>cN?_`@Lk_5~6BQ?Et!2*>igJ13t&%hTLv@B%M+2N8xH0gSUpvNTq?X4Kx7T zd~&~KxwKNt&X$R(JiBKbZ?l^Z{dxRVXgU)+xyaxG$haIN7;u>|_=y>}tF17++u89U zy?S|vFFlllH{i;S0JwRrMJD%Mr#`=3-DjdI*?Ql;)ZzWu;hjjeziZuZ0hs{)b>3om zFnv=}*&!d-ton$+ZzNiyDi^@1R*$kePdg9S%gL{Pr65u%Kbyyh zns5l8FJ+Oxc_2Ljl+QB;-K#QWw3V&xYc5d>w1=bY`3#VuRe;CafeE#lB7vsBw zJCOI2ZyR%0wOMk85s@Q>U(idpDR1HiYJ=m3 z|~Ar literal 0 HcmV?d00001 diff --git a/test/fixtures/bafyreicw73odv37k2pimrnyeadv5pejntop4xokrlrudvmnwu5t4gicaku.raw.bin b/test/fixtures/bafyreicw73odv37k2pimrnyeadv5pejntop4xokrlrudvmnwu5t4gicaku.raw.bin new file mode 100644 index 0000000000000000000000000000000000000000..e7ab3e2cec38564163ca8af8345ed432f27f8129 GIT binary patch literal 1488 zcmYMyX;hL~7{GDR%#s#$Qj9z<3203!W{Mddb<&CHq$ZV?OJzby37MKssklKnG zUnsFqN};rO>oWjN|LFsVLBVF}vjLiLf9T`Zt&bmc+y|$`QRyf3@04vkfPukJo7+7* zp0?>!{~7hN=O5pMa(!trh7HE($sH?Qsgf9)ty&(PflJu6EYco$Pd6w#e#ys z^PzZX7bjWG8;x`JPfv}`9ZH)a+uk10l0pHDxA^pG4f6sKlP_t$9b7s|30Pjbc>tN= zNN`?uaQ%HYfas<#LF(2d&n4k`4i?ucN~D{Q@y&Yfmn2*Wj3Z^&!~w{piDskbNH^u* zTR68?<{VEMe0q1&aIAou-mrA*W8^UaXHv?1YTBsCphA4def)NQuK=BGb;E5NJeP9x z=%|1IAi6d|evtj59+8ygB}E9E_`4!et*q{uZ*rA-`LY>q^AU_49==Lxi0%Sf8SvdsZeHB{EHWW zNMd}W<$fF16~i&^>9rk5bloMQ{d$#K1aU-&?vLmKu)bO(*iF(%EIrUubrlc&Ia*tk z>Q*_-O|@A%{Gz-V!0(X?S~C8X`k#wuxXo=78j~_3b2*}(>6+>4U-qV~9l&;i3FiqW z+^8~{9k?WePA{mf3~C|}Gux5n#f}NzgaCRj?dT;R9Ou}6^8X|Xi7cgev8I=IZgh$v zRaLq)d*1_4;s2d>lbvU6yx3T|Zfu`VXCGOOfZeT;oRxBhrU|J4idbU%dHLzN_f_-7 zx_sH4%Cqv)kXFqwD-~YzxZnFZfbXJ4yQ=Q(iNJbMXSw;tLKim&HBZe%^nUvwuvGc| z4&ZdbioMSh<2f&b_nwck)g-!y-V7(0hf(82*sT8$4=Hi)=gJi&^OB}uFh38QfSnYDwa(aj zOrmnl`QCi;+J!h18~w8yS0W54OfYa$KjIdiJu?-a7!=hqZIV%JspRh?m z`PNv7mCmbp0G?w7NcpQy;fbD?O#jBW&U)~LcP2EPl&c=mQ{BHV{J1dvq1S5|6idsUogFB)(A z98B;^e5$?sHP|ON;bLcUU4B1+e`VNyRyGd|z#kO+guq4XE}`G1QCLr>%yatTGOaZX zz~2m7V{*-4x6I$F+$TN0^z6To)+lpy{;bvIHM(GBKW;oX=1HmvQ|2EYV#nUT`~d$t U?B^w}bpyEbTZ-%_-xVJE9|Oyc!2kdN literal 0 HcmV?d00001 diff --git a/test/fixtures/bafyreicyir4fzeucvnesg3qkxzmdszs4ydlmjfn7teesksta5t3oeeprua.raw.bin b/test/fixtures/bafyreicyir4fzeucvnesg3qkxzmdszs4ydlmjfn7teesksta5t3oeeprua.raw.bin new file mode 100644 index 0000000000000000000000000000000000000000..3c0dcecc52b6eb05c84a8cad93499383eb49e29b GIT binary patch literal 1488 zcmYMydpOg39KdnfBc^Ccoc&rg%RQPM!^RV~hPi7fA#4W+naWnQqLVOcE{zUxY87%R zNn%!PIpTD4Dc4mew^NansVLX;>z{A`yr0ka`@Ej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russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Mon, 27 Nov 2023 18:59:44 -0800 Subject: [PATCH 2/6] feat: fix tests to prevent outbound network calls --- .aegir.js | 38 +++++++++++++++++---- .eslintrc | 3 +- DEVELOPER-NOTES.md | 9 +++++ bin/load-fixtures.sh | 8 +++++ test/.eslintrc | 3 +- test/lookupMultiple.node.spec.js | 57 ++++++++++++++++++++++++-------- 6 files changed, 97 insertions(+), 21 deletions(-) create mode 100644 DEVELOPER-NOTES.md create mode 100755 bin/load-fixtures.sh diff --git a/.aegir.js b/.aegir.js index 8d27e50..9c0dea8 100644 --- a/.aegir.js +++ b/.aegir.js @@ -1,3 +1,6 @@ +import http from 'node:http' +import fs from 'node:fs' + export default { tsRepo: false, dependencyCheck: { @@ -20,14 +23,37 @@ export default { } }, test: { - before: (...args) => { - if (args[0].runner === 'node') { - return { - env: { - NODE_OPTIONS: '--loader=esmock' - } + before: async (...args) => { + // set up a server to serve the fixtures + const server = http.createServer((req, res) => { + const cidString = req.url.replace('/ipfs/', '').split('?')[0] + const mockBlock = fs.readFileSync(`./test/fixtures/${cidString}.raw.bin`, null) + + res.writeHead(200, { + 'access-control-allow-origin': '*', // allow CORS requests + 'Content-Type': 'application/vnd.ipld.raw', + 'Content-Length': mockBlock.length + }) + res.end(mockBlock) + }) + let gwUrl = process.env.IPFS_GATEWAY + await new Promise((resolve, _reject) => { + server.listen(0, () => { + gwUrl = `http://localhost:${server.address().port}` + console.log(`server listening at ${gwUrl}`) + resolve() + }) + }) + return { + server, + env: { + IPFS_GATEWAY: gwUrl, + NODE_OPTIONS: '--loader=esmock' } } + }, + after: (_, before) => { + before.server.close() } } } diff --git a/.eslintrc b/.eslintrc index 92196a5..1292cb3 100644 --- a/.eslintrc +++ b/.eslintrc @@ -7,5 +7,6 @@ "parserOptions": { "sourceType": "module", "allowImportExportEverywhere": true - } + }, + "ignorePatterns": ["**/test/fixtures/**", "**/bin/load-fixtures.sh", "**/dist/**", "**/node_modules/**"], } diff --git a/DEVELOPER-NOTES.md b/DEVELOPER-NOTES.md new file mode 100644 index 0000000..bc3df6a --- /dev/null +++ b/DEVELOPER-NOTES.md @@ -0,0 +1,9 @@ +# Load fixtures + +We need to load a fixture with the following command: + +```bash +./bin/load-fixtures.sh bafyreif3tfdpr5n4jdrbielmcapwvbpcthepfkwq2vwonmlhirbjmotedi +``` + +then, we can do `npm run test:node -- -g 'lookup via HTTP Gateway'` to run a test that will tell us of any subsequent fixtures we need to load, and replace the CID in the above command with the CID that the test hangs on, and repeat. diff --git a/bin/load-fixtures.sh b/bin/load-fixtures.sh new file mode 100755 index 0000000..6cbed3a --- /dev/null +++ b/bin/load-fixtures.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +function main() { + local CID="$1" + curl -H "Accept: application/vnd.ipld.raw" "https://ipfs.io/ipfs/$CID?format=raw" > test/fixtures/$CID.raw.bin +} + +main "$@" diff --git a/test/.eslintrc b/test/.eslintrc index d117642..0cbc17f 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -1,5 +1,6 @@ { "rules": { "no-undef": 0 - } + }, + "ignorePatterns": ["**/fixtures/**"], } diff --git a/test/lookupMultiple.node.spec.js b/test/lookupMultiple.node.spec.js index 4d58150..b747f36 100644 --- a/test/lookupMultiple.node.spec.js +++ b/test/lookupMultiple.node.spec.js @@ -1,30 +1,61 @@ -import { decode as dagCborDecode } from '@ipld/dag-cbor' -import esmock from 'esmock' import { expect } from 'chai' +import { MAX_LOOKUP_RETRIES } from '../src/constants.js' +import fetch from 'cross-fetch' +import esmock from 'esmock' describe('[Runner Node]: lookup via HTTP Gateway supporting application/vnd.ipld.raw responses', function () { const ipfsGW = process?.env?.IPFS_GATEWAY || 'https://ipfs.io' + let rewiredGeoIp + let failedCalls = 0 + + beforeEach(async () => { + failedCalls = 0 + }) + afterEach(() => { + rewiredGeoIp = null + failedCalls = 0 + }) + it('looks up multiple times before failing', async () => { - let decodeCallCount = 0 - const rewiredGeoIp = await esmock('../src/index.js', {}, { - '@ipld/dag-cbor': { - decode: (...args) => { - decodeCallCount += 1 - if (decodeCallCount === 1) { - throw new Error('Decode Failed') + rewiredGeoIp = await esmock('../src/index.js', {}, { + 'cross-fetch': { + default: (gwUrl, options) => { + failedCalls++ + throw new Error('mock failure') + } + } + }) + + try { + await rewiredGeoIp.lookup(ipfsGW, '66.6.44.45') // use a different IP to avoid the cache + // should not reach here + expect.fail('should have thrown') + } catch (err) { + expect(err).to.have.property('message').to.contain('unable to fetch raw block for CID') + } finally { + expect(failedCalls).to.equal(MAX_LOOKUP_RETRIES) + } + }) + + it('returns successfully if MAX_LOOKUP_RETRIES is not reached', async () => { + rewiredGeoIp = await esmock('../src/index.js', {}, { + 'cross-fetch': { + default: (gwUrl, options) => { + if (failedCalls < MAX_LOOKUP_RETRIES - 1) { + failedCalls++ + throw new Error('mock failure') } - return dagCborDecode(...args) + return fetch(gwUrl, options) } } }) - const result = await rewiredGeoIp.lookup(ipfsGW, '66.6.44.4') - expect(decodeCallCount).to.be.greaterThan(1) + const result = await rewiredGeoIp.lookup(ipfsGW, '66.6.44.44') // use a different IP to avoid the cache + expect(failedCalls).to.be.greaterThan(1) expect( result ).to.be.eql({ - formatted: 'Ashburn, VA, USA, Earth', country_name: 'USA', country_code: 'US', region_code: 'VA', From 376f200a9f162b9bd91f210522bbb7369e000bda Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Mon, 27 Nov 2023 19:10:21 -0800 Subject: [PATCH 3/6] fix: update esmock and remove --loader option --- .aegir.js | 2 +- package-lock.json | 37 ++++++++----------------------------- package.json | 2 +- 3 files changed, 10 insertions(+), 31 deletions(-) diff --git a/.aegir.js b/.aegir.js index 9c0dea8..6e4e8a8 100644 --- a/.aegir.js +++ b/.aegir.js @@ -48,7 +48,7 @@ export default { server, env: { IPFS_GATEWAY: gwUrl, - NODE_OPTIONS: '--loader=esmock' + // NODE_OPTIONS: `--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("esmock", pathToFileURL("./"));` } } }, diff --git a/package-lock.json b/package-lock.json index ac79fbc..518d383 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "chai-as-promised": "^7.1.1", "cross-fetch": "^3.1.5", "csv-parse": "^5.3.0", - "esmock": "^2.0.6", + "esmock": "^2.6.0", "gauge": "^4.0.4", "ip": "^2.0.0", "it-concat": "^2.0.0", @@ -8340,13 +8340,10 @@ } }, "node_modules/esmock": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/esmock/-/esmock-2.0.6.tgz", - "integrity": "sha512-2EY6isqPxZ9xm/nPz7DE5u/M5Nt3Xq4WUTOT5Dv9sfaqim6HZ6hitpEEfrSKAryA1JsnF/YljSRo2MZCtx0LTw==", + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/esmock/-/esmock-2.6.0.tgz", + "integrity": "sha512-PFcxAm5bzPckh9V6s78FW+WaR/J+1R9K6vlItFOIFqNn+3w1pgo/HEEOJ2HBwVdrEnO7xXBgGUcFoNsdTU599A==", "dev": true, - "dependencies": { - "resolvewithplus": "^1.0.2" - }, "engines": { "node": ">=14.16.0" } @@ -19817,15 +19814,6 @@ "node": ">=4" } }, - "node_modules/resolvewithplus": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/resolvewithplus/-/resolvewithplus-1.0.2.tgz", - "integrity": "sha512-UNvTSqWpe1lhKvXb+Qo97Q/dFUtA0kDuUG/gO7S+P9H/xYZ+A9pwlAbY6Dqp2tgAeQNdHmQG5MdNL6d9/FWo6Q==", - "dev": true, - "engines": { - "node": ">=12.16.0" - } - }, "node_modules/responselike": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/responselike/-/responselike-2.0.1.tgz", @@ -28954,13 +28942,10 @@ "dev": true }, "esmock": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/esmock/-/esmock-2.0.6.tgz", - "integrity": "sha512-2EY6isqPxZ9xm/nPz7DE5u/M5Nt3Xq4WUTOT5Dv9sfaqim6HZ6hitpEEfrSKAryA1JsnF/YljSRo2MZCtx0LTw==", - "dev": true, - "requires": { - "resolvewithplus": "^1.0.2" - } + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/esmock/-/esmock-2.6.0.tgz", + "integrity": "sha512-PFcxAm5bzPckh9V6s78FW+WaR/J+1R9K6vlItFOIFqNn+3w1pgo/HEEOJ2HBwVdrEnO7xXBgGUcFoNsdTU599A==", + "dev": true }, "espree": { "version": "7.3.1", @@ -37092,12 +37077,6 @@ "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", "dev": true }, - "resolvewithplus": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/resolvewithplus/-/resolvewithplus-1.0.2.tgz", - "integrity": "sha512-UNvTSqWpe1lhKvXb+Qo97Q/dFUtA0kDuUG/gO7S+P9H/xYZ+A9pwlAbY6Dqp2tgAeQNdHmQG5MdNL6d9/FWo6Q==", - "dev": true - }, "responselike": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/responselike/-/responselike-2.0.1.tgz", diff --git a/package.json b/package.json index 33b3d0b..dfb4ffd 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "chai-as-promised": "^7.1.1", "cross-fetch": "^3.1.5", "csv-parse": "^5.3.0", - "esmock": "^2.0.6", + "esmock": "^2.6.0", "gauge": "^4.0.4", "ip": "^2.0.0", "it-concat": "^2.0.0", From 7f3a02f592360331c9c413544b7d167402e2c9ae Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Mon, 27 Nov 2023 19:12:33 -0800 Subject: [PATCH 4/6] fix: dont use text fixtures if IPFS_GATEWAY is set --- .aegir.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.aegir.js b/.aegir.js index 6e4e8a8..593ae5d 100644 --- a/.aegir.js +++ b/.aegir.js @@ -37,18 +37,21 @@ export default { res.end(mockBlock) }) let gwUrl = process.env.IPFS_GATEWAY - await new Promise((resolve, _reject) => { - server.listen(0, () => { - gwUrl = `http://localhost:${server.address().port}` - console.log(`server listening at ${gwUrl}`) - resolve() + if (!gwUrl) { + // no gateway specified, start the server + await new Promise((resolve, _reject) => { + server.listen(0, () => { + gwUrl = `http://localhost:${server.address().port}` + console.log(`server listening at ${gwUrl}`) + resolve() + }) }) - }) + } + return { server, env: { IPFS_GATEWAY: gwUrl, - // NODE_OPTIONS: `--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("esmock", pathToFileURL("./"));` } } }, From 45d2a72440cd22d81c2c55dd30adc64a9f053084 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Tue, 28 Nov 2023 08:10:14 -0800 Subject: [PATCH 5/6] chore: remove duplicate failedCalls in afterEach --- test/lookupMultiple.node.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/lookupMultiple.node.spec.js b/test/lookupMultiple.node.spec.js index b747f36..e4fbd8b 100644 --- a/test/lookupMultiple.node.spec.js +++ b/test/lookupMultiple.node.spec.js @@ -14,7 +14,6 @@ describe('[Runner Node]: lookup via HTTP Gateway supporting application/vnd.ipld }) afterEach(() => { rewiredGeoIp = null - failedCalls = 0 }) it('looks up multiple times before failing', async () => { From 4fef7499dc5cea56850530f34f767495b035baa8 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Tue, 28 Nov 2023 08:12:04 -0800 Subject: [PATCH 6/6] chore: .eslintrc formatting Co-authored-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- .eslintrc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 1292cb3..6da402c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -8,5 +8,10 @@ "sourceType": "module", "allowImportExportEverywhere": true }, - "ignorePatterns": ["**/test/fixtures/**", "**/bin/load-fixtures.sh", "**/dist/**", "**/node_modules/**"], + "ignorePatterns": [ + "**/bin/load-fixtures.sh", + "**/dist/**", + "**/node_modules/**", + "**/test/fixtures/**" + ], }