Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix requireActual fail with moduleNameMapper #8210

Merged
merged 5 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}));
});