Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: run tests on node.js v21 nightly #199

Merged
merged 24 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/node.js.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -54,7 +54,7 @@
"rewire"
],
"engines": {
"node": ">=14.16.0 <=19.9.0"
"node": ">=14.16.0"
},
"dependencies": {
"resolvewithplus": "^2.0.1"
Expand Down
2 changes: 2 additions & 0 deletions src/esmockCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => (
Expand Down
2 changes: 1 addition & 1 deletion src/esmockIsLoader.js
Original file line number Diff line number Diff line change
@@ -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)))()
13 changes: 10 additions & 3 deletions src/esmockLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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}
10 changes: 7 additions & 3 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -38,18 +40,20 @@
"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",
"test:node18-test-nodets": "cd tests-nodets && npm test",
"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"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/tests-ava/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/tests-tsm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down