Skip to content

Commit

Permalink
fix(@jest/resolve): Include stringifiedOptions in getModuleIDAsync (j…
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdavidson authored and F3n67u committed May 2, 2022
1 parent 5303e65 commit 4495619
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
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:899:17)
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:900:17)
at Object.require (index.js:10:1)"
`;

Expand Down Expand Up @@ -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)"
`;
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap
Expand Up @@ -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: <<REPLACED>>
Ran all test suites matching /native-esm.test.js/i."
Expand Down
9 changes: 9 additions & 0 deletions e2e/native-esm/__tests__/native-esm.test.js
Expand Up @@ -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);
});
Expand Down
8 changes: 8 additions & 0 deletions 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';
3 changes: 2 additions & 1 deletion packages/jest-resolve/src/resolver.ts
Expand Up @@ -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;
Expand Down

0 comments on commit 4495619

Please sign in to comment.