diff --git a/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap b/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap index b9c10e68936f..f9808e71e029 100644 --- a/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap +++ b/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap @@ -41,7 +41,7 @@ exports[`moduleNameMapper wrong array configuration 1`] = ` 12 | module.exports = () => 'test'; 13 | - at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:899:17) + at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:900:17) at Object.require (index.js:10:1)" `; @@ -70,6 +70,6 @@ exports[`moduleNameMapper wrong configuration 1`] = ` 12 | module.exports = () => 'test'; 13 | - at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:899:17) + at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:900:17) at Object.require (index.js:10:1)" `; diff --git a/e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap b/e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap index 6a6886d95fd3..aac14c4f8678 100644 --- a/e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap +++ b/e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap @@ -2,7 +2,7 @@ exports[`on node >=12.16.0 runs test with native ESM 1`] = ` "Test Suites: 1 passed, 1 total -Tests: 32 passed, 32 total +Tests: 33 passed, 33 total Snapshots: 0 total Time: <> Ran all test suites matching /native-esm.test.js/i." diff --git a/e2e/native-esm/__tests__/native-esm.test.js b/e2e/native-esm/__tests__/native-esm.test.js index 4a4088a7c2c2..494d67e62146 100644 --- a/e2e/native-esm/__tests__/native-esm.test.js +++ b/e2e/native-esm/__tests__/native-esm.test.js @@ -194,6 +194,15 @@ test('can mock module', async () => { expect(importedMock.foo).toEqual('bar'); }); +test('can mock transitive module', async () => { + jestObject.unstable_mockModule('../index.js', () => ({foo: 'bar'})); + + const importedMock = await import('../reexport.js'); + + expect(Object.keys(importedMock)).toEqual(['foo']); + expect(importedMock.foo).toEqual('bar'); +}); + test('supports imports using "node:" prefix', () => { expect(dns).toBe(prefixDns); }); diff --git a/e2e/native-esm/reexport.js b/e2e/native-esm/reexport.js new file mode 100644 index 000000000000..6cf18b68b96a --- /dev/null +++ b/e2e/native-esm/reexport.js @@ -0,0 +1,8 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +export * from './index.js'; diff --git a/packages/jest-resolve/src/resolver.ts b/packages/jest-resolve/src/resolver.ts index 4c9f1a93cae3..02b7c16634b7 100644 --- a/packages/jest-resolve/src/resolver.ts +++ b/packages/jest-resolve/src/resolver.ts @@ -590,7 +590,8 @@ export default class Resolver { moduleType + sep + (absolutePath ? absolutePath + sep : '') + - (mockPath ? mockPath + sep : ''); + (mockPath ? mockPath + sep : '') + + (stringifiedOptions ? stringifiedOptions + sep : ''); this._moduleIDCache.set(key, id); return id;