Open JakobJingleheimer opened 3 weeks ago
I can't reproduce:
import { before, mock } from 'node:test';
const logger = mock.fn();
before(async () => {
mock.module('./logger.ts', {
namedExports: { logger }
});
await import('./replace-js-ext-with-ts-ext.ts');
});
(node:745974) ExperimentalWarning: Type Stripping is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:745980) ExperimentalWarning: Type Stripping is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:745980) [MODULE_TYPELESS_PACKAGE_JSON] Warning: file:///index.test.ts parsed as an ES module because module syntax was detected; to avoid the performance penalty of syntax detection, add "type": "module" to /package.json
(node:745980) ExperimentalWarning: Module mocking is an experimental feature and might change at any time
✔ index.test.ts (93.695635ms)
ℹ tests 1
ℹ suites 0
ℹ pass 1
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 100.76966
You can see it here: https://github.com/JakobJingleheimer/correct-ts-specifiers/commit/6deda58539058ac0675d60afdd7d8d3cc69921c6
Just change the file extension of logger back to .ts
and run npm test
. It succeeds as .js
and fails as .ts
.
I am seeing the same issue when experimenting with these two flags.
I cannot reproduce on main, can you check?
I can actually
I haven't verified this issue, but I would expect it to be valid since the module-typescript
(and others) format was introduced, and the module mocking code explicitly checks for one of these formats.
It might be that it's tricky to reproduce when ambiguous files are used?
Version
22.6.0
Platform
Subsystem
module
What steps will reproduce the bug?
logger.ts
)replace-js-ext-with-ts-ext.test.ts
)Within the test file, set up a module mock
node --experimental-test-module-mocks --experimental-strip-types --test ./replace-js-ext-with-ts-ext.test.ts
)How often does it reproduce? Is there a required condition?
100%
What is the expected behavior? Why is that the expected behavior?
It should behave the same as when the module mock target is a node builtin or a javascript file.
What do you see instead?
Additional information
No response