Skip to content

Commit

Permalink
fix(resolve): remove faulty check for node: modules (#13806)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Jan 24, 2023
1 parent b404296 commit 7626da9
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -18,6 +18,7 @@
- `[@jest/expect-utils]` `toMatchObject` should handle `Symbol` properties ([#13639](https://github.com/facebook/jest/pull/13639))
- `[jest-mock]` Fix `mockReset` and `resetAllMocks` `undefined` return value([#13692](https://github.com/facebook/jest/pull/13692))
- `[jest-resolve]` Add global paths to `require.resolve.paths` ([#13633](https://github.com/facebook/jest/pull/13633))
- `[jest-resolve]` Correct node core module detection when using `node:` specifiers ([#13806](https://github.com/facebook/jest/pull/13806))
- `[jest-runtime]` Support WASM files that import JS resources ([#13608](https://github.com/facebook/jest/pull/13608))
- `[jest-runtime]` Use the `scriptTransformer` cache in `jest-runner` ([#13735](https://github.com/facebook/jest/pull/13735))
- `[jest-runtime]` Enforce import assertions when importing JSON in ESM ([#12755](https://github.com/facebook/jest/pull/12755) & [#13805](https://github.com/facebook/jest/pull/13805))
Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap
Expand Up @@ -41,7 +41,7 @@ exports[`moduleNameMapper wrong array configuration 1`] = `
12 | module.exports = () => 'test';
13 |
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:760:17)
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:759:17)
at Object.require (index.js:10:1)
at Object.require (__tests__/index.js:10:20)"
`;
Expand Down Expand Up @@ -71,7 +71,7 @@ exports[`moduleNameMapper wrong configuration 1`] = `
12 | module.exports = () => 'test';
13 |
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:760:17)
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:759:17)
at Object.require (index.js:10:1)
at Object.require (__tests__/index.js:10:20)"
`;
4 changes: 2 additions & 2 deletions packages/jest-resolve/src/__tests__/resolve.test.ts
Expand Up @@ -91,11 +91,11 @@ describe('isCoreModule', () => {
expect(isCore).toBe(true);
});

it('returns false if using `node:` URLs and `moduleName` is not a core module.', () => {
it('returns true if using `node:` URLs and `moduleName` is not a core module.', () => {
const moduleMap = ModuleMap.create('/');
const resolver = new Resolver(moduleMap, {} as ResolverConfig);
const isCore = resolver.isCoreModule('node:not-a-core-module');
expect(isCore).toBe(false);
expect(isCore).toBe(true);
});
});

Expand Down
4 changes: 1 addition & 3 deletions packages/jest-resolve/src/resolver.ts
Expand Up @@ -456,9 +456,7 @@ export default class Resolver {
isCoreModule(moduleName: string): boolean {
return (
this._options.hasCoreModules &&
(isBuiltinModule(moduleName) ||
(moduleName.startsWith('node:') &&
isBuiltinModule(moduleName.slice('node:'.length)))) &&
(isBuiltinModule(moduleName) || moduleName.startsWith('node:')) &&
!this._isAliasModule(moduleName)
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-runtime/src/index.ts
Expand Up @@ -1803,7 +1803,7 @@ export default class Runtime {
return this._getMockedNativeModule();
}

return require(moduleWithoutNodePrefix);
return require(moduleName);
}

private _importCoreModule(moduleName: string, context: VMContext) {
Expand Down

0 comments on commit 7626da9

Please sign in to comment.