Comments (3)
I use testdouble with ava and it seems to work on node 20.
Initially it started failing after upgrading to node 20, but switching loader ts-node/esm
to --import=tsimp/import
for TypeScript worked.
https://www.npmjs.com/package/tsimp
I appreciate you might not be using Ava, but this might help with whatever other test framework you are using.
My Ava config, for reference:
export default {
cache: false,
failWithoutAssertions: false,
extensions: {
ts: 'module'
},
nodeArguments: [
'--import=tsimp/import',
'--import=testdouble'
]
}
from testdouble.js.
This is almost surely caused by the testdouble loader's resolve
hook stomping other loaders' resolve hooks (perhaps a short-circuit?). This is the case for https://github.com/JakobJingleheimer/nodejs-loaders:
node --loader=testdouble --loader=nodejs-loaders/dev/tsx ./main.mts
// main.mts
import './foo.mts'; // the contents of foo.mts doesn't matter
node --loader=testdouble --loader=nodejs-loaders/dev/css-module ./main.mjs
// main.mjs
import './foo.module.css'; // the contents of foo.module.css doesn't matter
These work fine when --loader=testdouble
is removed.
This issue occurs in node v20 and node v21.
from testdouble.js.
I believe the issue may be caused by
https://github.com/testdouble/quibble/blob/main/lib/quibble.mjs#L58
https://github.com/testdouble/quibble/blob/main/lib/quibble.mjs#L66
There is more output from await resolve()
than just url
(format
and importAttributes
), and that omitted output must be included in the return:
try {
- const { url } = await resolve()
+ const { url, ...ctx } = await resolve()
const quibbledUrl = addQueryToUrl(url, '__quibble', stubModuleGeneration)
if (url.startsWith('node:') && !getStubsInfo(quibbledUrl)) {
return { url }
}
- return { url: quibbledUrl }
+ return { ...ctx, url: quibbledUrl }
} catch (error) {
I confirmed the above fixes the issue (by manually editing quibble in my node_modules
).
A caveat though: the above fix is potentially only half the cause. Quibble's query params dupe node's path.extname
(et al) as well as endsWith()
: path.extname('foo.mts?__quibble=0')
→ '.mts?__quibble=0'
, which can cause the other loaders (such as the ones I cited in the above #525 (comment)) to fail to recognise the file.
from testdouble.js.
Related Issues (20)
- ES module replacement changed in Node 18.6 HOT 5
- Using testdouble esm loader with ts-node/esm loader on mocha leads to errors (Node 18.6.0) HOT 24
- function identity is different for modules that are not replaced with testdouble when testdouble is replacing other ESM modules HOT 10
- Importing a mocked ESM module dynamically will throw an error in node 16.17.0 HOT 3
- td.replace support for constructors? HOT 2
- td.replaceEsm() but mocking a global in that module only HOT 2
- Consider relaxing `thenReject` to accept types other than `Error` HOT 2
- How to call-through original function? HOT 1
- Incompatibility with node v20.0.0 HOT 2
- Add docs for using `testdouble` when we have to use another loader (ie `ts-node/esm`) HOT 8
- Where is changelog for 3.19.0 HOT 2
- Get list of mocked modules HOT 7
- Feature request: reset specific module(s) HOT 6
- replaceEsm behaviour HOT 1
- `td.imitate` produces `undefined` for object keys of type `Accessor`
- `td.replaceEsm` does not work when specifier is resolved via loader HOT 1
- Feature request: `td.func().reset()` (reset spy/stub state)
- Suite test:esm fails under Node 21 HOT 2
- Module not found: Error: Can't resolve 'module' in 'node_modules/testdouble/lib'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from testdouble.js.