Hi there,
It doesn't seem to be possible to mock globals with Node's new --experimental-strip-types TypeScript support.
The following code correctly makes console.log do nothing when mocking a JS file but not a TS file:
const { someFunction } = await esmock.strict("./file.ts", {
import: {
console: {
log: () => {},
},
},
});
I've traced through the code and believe the issue is the regex on line 25 in esmockLoader.js. The new TypeScript support introduced a new format of module-typescript (possibly a CJS variant too, not checked) which the loader isn't aware of. I added the new format to the regex locally and it works as expected so it seems to be a simple fix.
I'm happy to contribute the change and a relevant test if you're happy with the above fix?
PS: esmock is brilliant, thanks for making it!
Hi there,
It doesn't seem to be possible to mock globals with Node's new
--experimental-strip-typesTypeScript support.The following code correctly makes
console.logdo nothing when mocking a JS file but not a TS file:I've traced through the code and believe the issue is the regex on line 25 in
esmockLoader.js. The new TypeScript support introduced a new format ofmodule-typescript(possibly a CJS variant too, not checked) which the loader isn't aware of. I added the new format to the regex locally and it works as expected so it seems to be a simple fix.I'm happy to contribute the change and a relevant test if you're happy with the above fix?
PS: esmock is brilliant, thanks for making it!