Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #517 from testdouble/make-auto-register-really-work
make Node 20.6.0 auto register _really_ work
  • Loading branch information
giltayar committed Sep 16, 2023
2 parents f9451a6 + d3e3a3a commit d7255e9
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion examples/babel/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/jest-broken/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/jest/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/node-ava/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/node-esm-auto-loader/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/node-esm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -41,15 +41,15 @@
"style": "run-p style:js style:ts",
"style:js": "standard --fix",
"style:ts": "standard --fix --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin \"**/*.ts\"",
"test": "run-s test:unit test:safe test:esm test:no-loader-esm test:example",
"test": "run-s test:unit test:safe test:esm test:esm-auto-loader test:no-loader-esm test:example",
"test:unit": "teenytest --helper test/helper.js \"test/unit/**/*.test.{js,ts}\"",
"test:safe": "teenytest --helper test/helper.js \"test/safe/**/*.test.{js,ts}\"",
"test:esm": "cross-env NODE_OPTIONS=\"--loader=quibble\" TS_NODE_IGNORE=\"node_modules,notypescript\" ./test/safe-esm/teenytest-proxy.js --helper test/helper.js test/safe-esm/replace.test.js",
"test:esm-auto-loader": "node test/esm-lib/supports-auto-load.js not || TS_NODE_IGNORE=\"node_modules,notypescript\" ./test/safe-esm/teenytest-proxy.js --helper test/helper.js test/safe-esm/replace.test.js",
"test:no-loader-esm": "node test/esm-lib/supports-auto-load.js || cross-env TS_NODE_IGNORE=\"node_modules,notypescript\" teenytest test/helper.js './test/safe-esm/*.no-loader-test.{mjs,js}'",
"test:esm-auto-loader": "node test/support/supports-auto-load.js not || cross-env TS_NODE_IGNORE=\"node_modules,notypescript\" ./test/safe-esm/teenytest-proxy.js --helper test/helper.js test/safe-esm/replace.test.js",
"test:no-loader-esm": "node test/support/supports-auto-load.js || cross-env TS_NODE_IGNORE=\"node_modules,notypescript\" teenytest test/helper.js './test/safe-esm/*.no-loader-test.{mjs,js}'",
"test:ci": "npm run compile && run-p style test && echo \"All done!\"",
"test:example": "run-s test:example:babel test:example:jest test:example:jest-broken test:example:node test:example:node-ava test:example:node-esm",
"test:example-esm-auto-loader": "node test/esm-lib/supports-auto-load.js not || npm run test:example:node-esm-auto-loader",
"test:example": "run-s test:example:babel test:example:jest test:example:jest-broken test:example:node test:example:node-ava test:example:node-esm test:example-esm-auto-loader",
"test:example-esm-auto-loader": "node test/support/supports-auto-load.js not || npm run test:example:node-esm-auto-loader",
"test:example:babel": "bash ./script/run-examples babel",
"test:example:jest": "bash ./script/run-examples jest",
"test:example:jest-broken": "bash ./script/run-examples jest-broken",
Expand Down
9 changes: 9 additions & 0 deletions src/can-register-loader.js
@@ -0,0 +1,9 @@
function canRegisterLoader () {
const [major, minor] = process.versions.node
.split('.')
.map((m) => parseInt(m, 10))

return major > 20 || (major === 20 && minor >= 6)
}

exports.canRegisterLoader = canRegisterLoader
3 changes: 2 additions & 1 deletion src/replace/index.js
Expand Up @@ -2,6 +2,7 @@ import _ from '../wrap/lodash'
import * as quibble from 'quibble'
import replaceModule, { replaceEsModule } from './module'
import replaceProperty from './property'
import { canRegisterLoader } from '../can-register-loader'

quibble.ignoreCallsFromThisFile()

Expand All @@ -14,7 +15,7 @@ export default function (target) {
}

export function replaceEsm (_modulePath, _namedExportReplacement, _defaultExportReplacement) {
if (!quibble.isLoaderLoaded()) {
if (!canRegisterLoader() && !quibble.isLoaderLoaded()) {
throw new Error('testdouble ESM loader not loaded. You cannot replace ES modules without a loader. Run node with `--loader=testdouble`.')
}
// Sending arguments instead of the above arguments is crucial because `replaceEsModule`
Expand Down
2 changes: 1 addition & 1 deletion test/support/supports-auto-load.js
@@ -1,4 +1,4 @@
const { canRegisterLoader } = require('../../lib/canRegisterLoader.js')
const { canRegisterLoader } = require('../../lib/can-register-loader')

if (process.argv[2] === 'not') {
process.exit(!canRegisterLoader() ? 0 : 1)
Expand Down

0 comments on commit d7255e9

Please sign in to comment.