jest
jest copied to clipboard
[Bug]: `jest.unstable_mockModule` does not work with custom dynamic import wrapper
Version
29.7.0
Steps to reproduce
https://github.com/conventional-changelog/commitlint/pull/3850
yarn test-ci
Expected behavior
No error
Actual behavior
RUNS @commitlint/load/src/utils/load-plugin.test.ts
/Users/JounQin/Workspaces/GitHub/commitlint/@commitlint/load/src/utils/load-plugin.ts:35
throw new MissingPluginError(pluginName, message, {
^
MissingPluginError: Failed to load plugin example: Cannot find module 'commitlint-plugin-example' from '@commitlint/load/src/utils/load-plugin.ts'
at loadPlugin (/Users/JounQin/Workspaces/GitHub/commitlint/@commitlint/load/src/utils/load-plugin.ts:35:23) {
['__proto__']: [Function: Error] {
stackTraceLimit: 100,
prepareStackTrace: [Function: prepareStackTrace]
},
messageTemplate: 'plugin-missing',
messageData: {
pluginName: 'commitlint-plugin-example',
commitlintPath: '/Users/JounQin/Workspaces/GitHub/commitlint/@commitlint/load'
}
}
Additional context
I've also tried 30.0.0-alpha.2 locally but still failed.
Environment
System:
OS: macOS 14.2.1
CPU: (10) arm64 Apple M1 Max
Binaries:
Node: 18.19.0 - ~/Library/Caches/fnm_multishells/43242_1705330700273/bin/node
Yarn: 1.22.19 - ~/Library/Caches/fnm_multishells/43242_1705330700273/bin/yarn
npm: 10.2.3 - ~/Library/Caches/fnm_multishells/43242_1705330700273/bin/npm
npmPackages:
jest: ^29.7.0 => 29.7.0
Related codes:
const dynamicImport = async <T,>(id: string): Promise<T> => {
const imported = await import(
path.isAbsolute(id) ? pathToFileURL(id).toString() : id
);
return ("default" in imported && imported.default) || imported;
};
try {
plugin = await dynamicImport<Plugin>(longName);
} catch (pluginLoadErr) {}
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
ping
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
Can you put together a minimal reproduction?