Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: jest.unstable_mockModule does not work with custom dynamic import wrapper #14856

Open
JounQin opened this issue Jan 15, 2024 · 5 comments

Comments

@JounQin
Copy link

JounQin commented Jan 15, 2024

Version

29.7.0

Steps to reproduce

conventional-changelog/commitlint#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
@JounQin
Copy link
Author

JounQin commented Jan 15, 2024

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) {}

Copy link

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.

@github-actions github-actions bot added the Stale label Feb 14, 2024
@JounQin
Copy link
Author

JounQin commented Feb 15, 2024

ping

@github-actions github-actions bot removed the Stale label Feb 15, 2024
Copy link

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.

@SimenB
Copy link
Member

SimenB commented Mar 17, 2024

Can you put together a minimal reproduction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants