Version
29.7.0
Steps to reproduce
- Open https://stackblitz.com/edit/stackblitz-starters-7snujh
- Run
jest in a terminal
- Notice failing tests
Expected behavior
Tests are simple and assert require.resolve() behavior:
it('require-resolve', () => {
const result = require.resolve('@foo/js');
expect(typeof result).toBe('string');
expect(result).toMatch(/\/js\/index.js$/);
});
it('require-resolve-paths', () => {
const paths = [__dirname];
const result = require.resolve('@foo/js', { paths });
expect(typeof result).toBe('string');
expect(result).toMatch(/\/src\/\@foo\/js\/index.js$/);
});
The expectation is that both tests will pass.
Actual behavior
require-resolve-paths test is failing with:
Message:
Cannot resolve module '@foo/js' from paths ['/home/projects/stackblitz-starters-7snujh/packages'] from /home/projects/stackblitz-starters-7snujh/packages/require-resolve-paths.test.js
While moduleNameMapper is configured:
module.exports = {
moduleNameMapper: {
'@foo/js': '<rootDir>/js/index.js',
},
}
It fails because once options.paths are used, completely different branch is used:
|
const {paths} = options; |
|
if (paths) { |
|
for (const p of paths) { |
|
const absolutePath = path.resolve(from, '..', p); |
|
const module = this._resolver.resolveModuleFromDirIfExists( |
resolveModuleFromDirIfExists() does not check for moduleNameMapper config unlike _resolveCjsModule() (or actually resolveModule() that is used in a default scenario.
Additional context
No response
Environment
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Binaries:
Node: 18.18.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 9.4.2 - /usr/local/bin/npm
pnpm: 8.6.12 - /usr/local/bin/pnpm
npmPackages:
jest: ^29.7.0 => 29.7.0
Version
29.7.0
Steps to reproduce
jestin a terminalExpected behavior
Tests are simple and assert
require.resolve()behavior:The expectation is that both tests will pass.
Actual behavior
require-resolve-pathstest is failing with:While
moduleNameMapperis configured:It fails because once
options.pathsare used, completely different branch is used:jest/packages/jest-runtime/src/index.ts
Lines 1458 to 1462 in 1bacb5e
resolveModuleFromDirIfExists()does not check formoduleNameMapperconfig unlike_resolveCjsModule()(or actuallyresolveModule()that is used in a default scenario.Additional context
No response
Environment
System: OS: Linux 5.0 undefined CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Binaries: Node: 18.18.0 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 9.4.2 - /usr/local/bin/npm pnpm: 8.6.12 - /usr/local/bin/pnpm npmPackages: jest: ^29.7.0 => 29.7.0