From d8af0bab9d1045d28ac85b8f8ed697cf3449947d Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 17 Oct 2024 12:39:07 -0700 Subject: [PATCH 1/4] add log function for debugging loader --- CHANGELOG.md | 2 ++ src/esmockLoader.js | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e5e0ee..467a44b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # changelog + * 2.6.8 _tbd_ + * add log utility for debugging loader * 2.6.7 _Jul.16.2024_ * [add swc tests and remove swc caution from README](https://github.com/iambumblehead/esmock/pull/309) thanks @Brooooooklyn * [unpin node 22.1 at test CI](https://github.com/iambumblehead/esmock/pull/309) and use latest 22.x diff --git a/src/esmockLoader.js b/src/esmockLoader.js index 9770fc8..0b16977 100644 --- a/src/esmockLoader.js +++ b/src/esmockLoader.js @@ -1,4 +1,4 @@ -import fs from 'node:fs/promises' +import fs from 'node:fs' import module from 'node:module' import process from 'process' import esmockErr from './esmockErr.js' @@ -33,6 +33,10 @@ const moduleIdReCreate = (moduleid, treeid) => new RegExp( const mockKeys = global.mockKeys = (global.mockKeys || {}) const mockKeysSource = global.mockKeysSource = (global.mockKeysSource || {}) +// use fs when logging from hooks, console.log async unpredictable +const log = (...args) => ( + fs.writeSync(1, JSON.stringify(args, null, ' ').slice(2, -1))) + // node v20.0-v20.6 const globalPreload = !module.register && (({ port }) => ( port.addEventListener('message', ev => ( @@ -170,7 +174,7 @@ const load = async (url, context, nextLoad) => { const sourceIsNullLike = ( nextLoadRes.source === null || nextLoadRes.source === undefined) const source = sourceIsNullLike - ? String(await fs.readFile(new URL(url))) + ? String(fs.readFileSync(new URL(url))) : String(nextLoadRes.source) const hbang = (source.match(hashbangRe) || [])[0] || '' const sourcesafe = hbang ? source.replace(hashbangRe, '') : source From 9ff0367f876bb48003d9f367d98d27029f9eebed Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 17 Oct 2024 12:46:09 -0700 Subject: [PATCH 2/4] update eslint to ignore log --- eslint.config.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/eslint.config.js b/eslint.config.js index f3e5700..e4f2b00 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -17,6 +17,7 @@ export default [ rules: { "@typescript-eslint/no-unused-expressions": 0, "@typescript-eslint/no-explicit-any": 0, + "@typescript-eslint/no-unused-vars": 0, "comma-dangle": "off" } }, @@ -47,6 +48,7 @@ export default [ "no-unused-vars": ["error", { "vars": "all", "args": "after-used", + "varsIgnorePattern": "log", "ignoreRestSiblings": false }], "global-require": 0, From 3bbff0e4d99ad2783da0f5464af88b0b0851a3cc Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 17 Oct 2024 13:33:53 -0700 Subject: [PATCH 3/4] update dependencies, drop ava and jest from test sequence --- CHANGELOG.md | 3 ++- README.md | 2 ++ tests/package.json | 8 ++++---- tests/tests-ava/package.json | 2 +- tests/tests-jest/package.json | 2 +- tests/tests-mocha/package.json | 10 +++++----- tests/tests-mocha/test/app.test.js | 8 ++++---- tests/tests-source-map/package.json | 10 +++++----- tests/tests-tsx/package.json | 2 +- 9 files changed, 25 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 467a44b..d85dbc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # changelog * 2.6.8 _tbd_ - * add log utility for debugging loader + * [add log utility function](https://github.com/iambumblehead/esmock/pull/314) for debugging loader + * [dropped ava and jest](https://github.com/iambumblehead/esmock/pull/314) from test sequence, node v22 --loader issues * 2.6.7 _Jul.16.2024_ * [add swc tests and remove swc caution from README](https://github.com/iambumblehead/esmock/pull/309) thanks @Brooooooklyn * [unpin node 22.1 at test CI](https://github.com/iambumblehead/esmock/pull/309) and use latest 22.x diff --git a/README.md b/README.md index 6d92907..8363131 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ _**Note: For versions of node prior to v20.6.0,** "--loader" command line arguments must be used with `esmock` as demonstrated [in the wiki.][4] Current versions of node do not require "--loader"._ +_**Note: due to --loader issues at node v22,** support for `ava` and `jest` are dropped._ + `esmock` has the below signature ```js await esmock( diff --git a/tests/package.json b/tests/package.json index 6bd65bc..ae7addb 100644 --- a/tests/package.json +++ b/tests/package.json @@ -50,17 +50,17 @@ "install:all": "node --version && npm install && npm-run-all install:test*", "test:test-uvu": "cd tests-uvu && npm test", "test:test-mocha": "cd tests-mocha && npm test", - "test:test-ava": "cd tests-ava && npm test", + "test-dropped:test-ava": "cd tests-ava && npm test", "test:test-tsx": "cd tests-tsx && npm test", "test:test-swc": "cd tests-swc && 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-tsx": "cd tests-tsx && npm run test", "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-dropped:node18-test-jest": "cd tests-jest && npm test", + "test-dropped: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-dropped:node18-test-source-map": "cd tests-source-map && npm test", "test:node18-test-no-loader": "cd tests-no-loader && npm test", "test:node18-test-workspaces": "cd tests-workspaces && npm test", "test:node18:all": "npm run isnodelt18 || npm-run-all test:node18-test*", diff --git a/tests/tests-ava/package.json b/tests/tests-ava/package.json index 457ac90..b389805 100644 --- a/tests/tests-ava/package.json +++ b/tests/tests-ava/package.json @@ -6,7 +6,7 @@ "url": "git+https://github.com/iambumblehead/esmock.git" }, "dependencies": { - "ava": "^5.3.1", + "ava": "^6.1.3", "run-script-os": "^1.1.6", "esmock": "file:..", "sinon": "file:../node_modules/sinon", diff --git a/tests/tests-jest/package.json b/tests/tests-jest/package.json index 217efd7..f0dfd66 100644 --- a/tests/tests-jest/package.json +++ b/tests/tests-jest/package.json @@ -7,7 +7,7 @@ }, "dependencies": { "jest": "^29.6.2", - "jest-light-runner": "0.5.0", + "jest-light-runner": "0.6.0", "run-script-os": "^1.1.6", "esmock": "file:..", "sinon": "file:../node_modules/sinon", diff --git a/tests/tests-mocha/package.json b/tests/tests-mocha/package.json index 27fa761..992da31 100644 --- a/tests/tests-mocha/package.json +++ b/tests/tests-mocha/package.json @@ -6,12 +6,12 @@ "url": "git+https://github.com/iambumblehead/esmock.git" }, "dependencies": { - "mocha": "^10.2.0", - "chai": "^4.3.7", - "chai-http": "^4.4.0", + "mocha": "^10.7.3", + "chai": "^5.1.1", + "chai-http": "^5.1.1", "esmock": "file:..", - "express": "^4.18.2", - "passport": "^0.6.0" + "express": "^4.21.1", + "passport": "^0.7.0" }, "scripts": { "isnodelt20_6": "node -e \"(([mj, mn]) => (+mj < 20 || (+mj === 20 && +mn < 6)))(process.versions.node.split('.')) || process.exit(1)\"", diff --git a/tests/tests-mocha/test/app.test.js b/tests/tests-mocha/test/app.test.js index 85002f2..90f3c28 100644 --- a/tests/tests-mocha/test/app.test.js +++ b/tests/tests-mocha/test/app.test.js @@ -1,5 +1,5 @@ -import chai from 'chai' -import chaiHttp from 'chai-http' +import * as chai from 'chai' +import {default as chaiHttp, request} from 'chai-http' import esmock from 'esmock' chai.use(chaiHttp) @@ -14,8 +14,8 @@ const app = await esmock('../src/app.js', { describe('/', () => { it('should work', done => { try { - chai - .request(app.default) + request + .execute(app) .get('/') .end((err, res) => { app.close() diff --git a/tests/tests-source-map/package.json b/tests/tests-source-map/package.json index bd631b2..5036f9f 100644 --- a/tests/tests-source-map/package.json +++ b/tests/tests-source-map/package.json @@ -7,13 +7,13 @@ }, "dependencies": { "esmock": "file:..", - "@ava/typescript": "^4.1.0", + "@ava/typescript": "^5.0.0", "@tsconfig/node16": "^16.1.0", - "@types/node": "^20.4.5", - "ava": "^5.3.1", + "@types/node": "^22.7.6", + "ava": "^6.1.3", "cross-env": "^7.0.3", - "rimraf": "^5.0.1", - "typescript": "^5.1.6" + "rimraf": "^6.0.1", + "typescript": "^5.6.3" }, "scripts": { "isnodelt20_6": "node -e \"(([mj, mn]) => (+mj < 20 || (+mj === 20 && +mn < 6)))(process.versions.node.split('.')) || process.exit(1)\"", diff --git a/tests/tests-tsx/package.json b/tests/tests-tsx/package.json index dfe9354..6ab12f0 100644 --- a/tests/tests-tsx/package.json +++ b/tests/tests-tsx/package.json @@ -16,6 +16,6 @@ "test": "npm run isloaderavailable && npm run test:loader || npm run test:current" }, "devDependencies": { - "@types/node": "^20.14.2" + "@types/node": "^22.7.6" } } From cddb5bca8b50cc7ab176e4d2432678dae0bbef76 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 17 Oct 2024 13:41:27 -0700 Subject: [PATCH 4/4] smaller note at README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8363131..211580c 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ _**Note: For versions of node prior to v20.6.0,** "--loader" command line arguments must be used with `esmock` as demonstrated [in the wiki.][4] Current versions of node do not require "--loader"._ -_**Note: due to --loader issues at node v22,** support for `ava` and `jest` are dropped._ +_**Note: due to --loader issues,** support for `ava` and `jest` are dropped._ `esmock` has the below signature ```js