Skip to content

Commit

Permalink
Fix requireActual fail with moduleNameMapper (#8210)
Browse files Browse the repository at this point in the history
* Fix requireActual fail with moduleNameMapper

* update changelog

* update PR link

* fix PR number

* fix CHANGELOG
  • Loading branch information
levinqdl authored and thymikee committed Mar 27, 2019
1 parent 4b3483e commit 0f43bdd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- `[jest-resolve-dependencies]`: Remove internal peer dependencies ([#8215](https://github.com/facebook/jest/pull/8215))
- `[jest-resolve]`: Remove internal peer dependencies ([#8215](https://github.com/facebook/jest/pull/8215))
- `[jest-snapshot]`: Remove internal peer dependencies ([#8215](https://github.com/facebook/jest/pull/8215))
- `[jest-resolve]` Fix requireActual with moduleNameMapper ([#8210](https://github.com/facebook/jest/pull/8210))

### Chore & Maintenance

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ FAIL __tests__/index.js
12 | module.exports = () => 'test';
13 |
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:473:17)
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:471:17)
at Object.require (index.js:10:1)
`;
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ FAIL __tests__/test.js
| ^
4 |
at Resolver.resolveModule (../../packages/jest-resolve/build/index.js:231:17)
at Resolver.resolveModule (../../packages/jest-resolve/build/index.js:229:17)
at Object.require (index.js:3:18)
`;
8 changes: 3 additions & 5 deletions packages/jest-resolve/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,9 @@ class Resolver {
options?: Resolver.ResolveModuleConfig,
): Config.Path {
const dirname = path.dirname(from);
const module = this.resolveModuleFromDirIfExists(
dirname,
moduleName,
options,
);
const module =
this.resolveStubModuleName(from, moduleName) ||
this.resolveModuleFromDirIfExists(dirname, moduleName, options);
if (module) return module;

// 5. Throw an error if the module could not be found. `resolve.sync` only
Expand Down
13 changes: 13 additions & 0 deletions packages/jest-runtime/src/__tests__/runtime_require_actual.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,17 @@ describe('Runtime requireActual', () => {
);
expect(exports.isManualMockModule).toBe(false);
}));

test('requireActual with moduleNameMapper', () =>
createRuntime(__filename, {
moduleNameMapper: {
'^testMapped/(.*)': '<rootDir>/mapped_dir/$1',
},
}).then(runtime => {
const exports = runtime.requireActual(
runtime.__mockRootPath,
'testMapped/moduleInMapped',
);
expect(exports).toBe('in_mapped');
}));
});

0 comments on commit 0f43bdd

Please sign in to comment.