diff --git a/.github/workflows/node.js.yml b/.github/workflows/test.yml similarity index 87% rename from .github/workflows/node.js.yml rename to .github/workflows/test.yml index b67b04ae..8fceb3a9 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/test.yml @@ -14,11 +14,13 @@ jobs: runs-on: ${{ matrix.os }} timeout-minutes: 12 strategy: + fail-fast: false matrix: # node-14's npm must be updated, but no longer updatable due to: # https://github.com/npm/cli/issues/2663 # because of this, node-14 test strategy is removed :( - node-version: [16.x, 18.x, 19.x] + # node-version: [16.x, 18.x, 19.x, 20.x, 20-nightly] + node-version: [16.x, 18.x, 19.x, 21-nightly] os: [ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v3 diff --git a/CHANGELOG.md b/CHANGELOG.md index f53a21ff..dd28749e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # changelog + * 2.2.3 _May.16.2023_ + * [add node v21 nightly](https://github.com/iambumblehead/esmock/pull/199) to test ci pipeline + * send wide uri definitions to loader using loader worker + * [encountered upstream error](https://github.com/nodejs/node/issues/47614) when attempting to add node v20 tests * 2.2.2 _May.06.2023_ * [detect async import.meta.resolve](https://github.com/iambumblehead/esmock/pull/201) and handle in a separate way * remove un-necessary usage of await keyword in README example diff --git a/README.md b/README.md index 74962a40..cc2569c0 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,10 @@ "test-ts": "node --loader=ts-node/esm --loader=esmock --test *ts", "test-jest": "NODE_OPTIONS=--loader=esmock jest" }, + "ava": [ + "ava is incompatible w/ --loader and node v20 or greater", + "https://github.com/avajs/ava/issues/3195" + ], "jest": { "runner": "jest-light-runner" } diff --git a/package.json b/package.json index 294e14d8..7c3e7f5e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "esmock", "type": "module", - "version": "2.2.2", + "version": "2.2.3", "license": "ISC", "readmeFilename": "README.md", "description": "provides native ESM import mocking for unit tests", @@ -54,7 +54,7 @@ "rewire" ], "engines": { - "node": ">=14.16.0 <=19.9.0" + "node": ">=14.16.0" }, "dependencies": { "resolvewithplus": "^2.0.1" diff --git a/src/esmockCache.js b/src/esmockCache.js index c092086a..51c625b6 100644 --- a/src/esmockCache.js +++ b/src/esmockCache.js @@ -7,6 +7,8 @@ const esmockCache = { } const esmockTreeIdSet = (key, keylong) => ( + typeof global.postMessageEsmk === 'function' + && global.postMessageEsmk({ key, keylong }), global.mockKeys[String(key)] = keylong) const esmockTreeIdGet = key => ( diff --git a/src/esmockIsLoader.js b/src/esmockIsLoader.js index 2714ab45..3aa07def 100644 --- a/src/esmockIsLoader.js +++ b/src/esmockIsLoader.js @@ -1,4 +1,4 @@ import { loaderIsVerified } from './esmockLoader.js' export default (c => async () => - c || (c = await loaderIsVerified(import.meta.url)))() + (c = c || loaderIsVerified(import.meta.url)))() diff --git a/src/esmockLoader.js b/src/esmockLoader.js index 6b5c3d74..aa2342df 100644 --- a/src/esmockLoader.js +++ b/src/esmockLoader.js @@ -16,6 +16,13 @@ const withHashRe = /.*#-#/ const isesmRe = /isesm=true/ const isnotfoundRe = /isfound=false/ +const globalPreload = (({ port }) => ( + port.addEventListener('message', ev => ( + global.mockKeys[ev.data.key] = ev.data.keylong)), + port.unref(), + 'global.postMessageEsmk = d => port.postMessage(d)' +)) + // new versions of node: when multiple loaders are used and context // is passed to nextResolve, the process crashes in a recursive call // see: /esmock/issues/#48 @@ -28,8 +35,8 @@ const nextResolveCall = async (nextResolve, specifier, context) => ( context.parentURL && (context.conditions.slice(-1)[0] === 'node-addons' || context.importAssertions || isLT1612) - ? await nextResolve(specifier, context) - : await nextResolve(specifier)) + ? nextResolve(specifier, context) + : nextResolve(specifier)) const resolve = async (specifier, context, nextResolve) => { const { parentURL } = context @@ -123,4 +130,4 @@ const load = async (url, context, nextLoad) => { // node lt 16.12 require getSource, node gte 16.12 warn remove getSource const getSource = isLT1612 && load -export {load, resolve, getSource, loaderIsVerified} +export {load, resolve, getSource, loaderIsVerified, globalPreload} diff --git a/tests/package.json b/tests/package.json index 8b936552..5832811f 100644 --- a/tests/package.json +++ b/tests/package.json @@ -26,6 +26,8 @@ "scripts": { "mini": "cd .. && cd src && npx esbuild esmock.js --minify --bundle --allow-overwrite --platform=node --format=esm --outfile=esmock.js", "isnodelt18": "node -e \"+process.versions.node.split('.')[0] < 18 || process.exit(1)\"", + "isnodegt19": "node -e \"+process.versions.node.split('.')[0] > 19 || process.exit(1)\"", + "isnodenight": "node -e \"process.versions.node.includes('night') || process.exit(1)\"", "install:esmock": "cd .. && npm install", "install:test-ava": "cd tests-ava && npm install", "install:test-uvu": "cd tests-uvu && npm install", @@ -38,10 +40,10 @@ "install:test-nodets": "cd tests-nodets && npm install", "install:test-mocha": "cd tests-mocha && npm install", "install:all": "node --version && npm install && npm-run-all install:test*", - "test:test-ava": "cd tests-ava && npm test", "test:test-uvu": "cd tests-uvu && npm test", "test:test-mocha": "cd tests-mocha && npm test", - "test:node18-test-tsm": "cd tests-tsm && npm test", + "test:node19-tsm": " cd tests-tsm && npm test", + "test:node18-test-tsm": "npm run isnodenight || npm run test:node19-tsm", "test:node18-test-node": "cd tests-node && npm test", "test:node18-test-jest": "cd tests-jest && npm test", "test:node18-test-jest-ts": "cd tests-jest-ts && npm test", @@ -49,7 +51,9 @@ "test:node18-test-source-map": "cd tests-source-map && npm test", "test:node18-test-no-loader": "cd tests-no-loader && npm test", "test:node18:all": "npm run isnodelt18 || npm-run-all test:node18-test*", - "test:all": "npm-run-all test:test* && npm run test:node18:all", + "test:nodelt20-test-ava": "cd tests-ava && npm test", + "test:nodelt20:all": "npm run isnodegt19 || npm-run-all test:nodelt20-test*", + "test:all": "npm-run-all test:test* && npm run test:node18:all && npm run test:nodelt20:all", "test:all-cover": "c8 --src=../src/* npm run test:all", "test:all-ci": "npm run mini && npm run test:all" } diff --git a/tests/tests-ava/package.json b/tests/tests-ava/package.json index 366e37d3..42a43ceb 100644 --- a/tests/tests-ava/package.json +++ b/tests/tests-ava/package.json @@ -6,7 +6,7 @@ "url": "https://github.com/iambumblehead/esmock.git" }, "dependencies": { - "ava": "^4.3.3", + "ava": "^5.2.0", "esmock": "file:..", "sinon": "file:../node_modules/sinon", "eslint": "file:../node_modules/eslint", diff --git a/tests/tests-tsm/package.json b/tests/tests-tsm/package.json index 8600df41..5c76b27c 100644 --- a/tests/tests-tsm/package.json +++ b/tests/tests-tsm/package.json @@ -6,7 +6,7 @@ "url": "https://github.com/iambumblehead/esmock.git" }, "dependencies": { - "tsm": "^2.2.2", + "tsm": "^2.3.0", "esmock": "file:..", "pg": "file:../node_modules/pg", "sinon": "file:../node_modules/sinon",