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]: globalSetup doesn't process moduleNameMappers #15037

Open
cope opened this issue Apr 25, 2024 · 1 comment
Open

[Bug]: globalSetup doesn't process moduleNameMappers #15037

cope opened this issue Apr 25, 2024 · 1 comment

Comments

@cope
Copy link

cope commented Apr 25, 2024

Version

29.7.0

Steps to reproduce

	moduleNameMapper: {
		'@/(.*)': ['<rootDir>/src/$1'],
		'test/(.*)': ['<rootDir>/test/$1']
	},
	globalSetup: '<rootDir>/test/_setup/setupTests.ts',

In setupTests.ts just import anything from source using '@/...' and it will fail with: Error: Jest: Got error running globalSetup - Cannot find module.

Moving setupTests.ts to setupFiles does not break.
But I do not want to run it before each and every test.

Expected behavior

Expected to work.

Actual behavior

Fails with: Error: Jest: Got error running globalSetup - Cannot find module.

Additional context

Duplicate of #6179, but @wanton7 solution just caused more weird issues to deal with.

I tried replacing the shortcut import with a full one, which loads the first file, but then fails within that one... so I would have to change many files to remove short imports which is a pain.

Environment

System:
    OS: Windows 10 10.0.19045
    CPU: (16) x64 Intel(R) Core(TM) i7-10875H CPU @ 2.30GHz
  Binaries:
    Node: 22.0.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - C:\Program Files\nodejs\yarn.CMD
    npm: 10.5.1 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.0.6 - C:\Program Files\nodejs\pnpm.CMD
  npmPackages:
    jest: ^29.7.0 => 29.7.0
@benasher44
Copy link

Dup of #11644

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