Skip to content
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 @@ -11,6 +11,7 @@
- `[jest-circus]` [**BREAKING**] Fail tests if a test takes a done callback and have return values ([#9129](https://github.com/facebook/jest/pull/9129))
- `[jest-circus]` [**BREAKING**] Throw a proper error if a test / hook is defined asynchronously ([#8096](https://github.com/facebook/jest/pull/8096))
- `[jest-config, jest-resolve]` [**BREAKING**] Remove support for `browser` field ([#9943](https://github.com/facebook/jest/pull/9943))
- `[jest-resolve]` Show relative path from root dir for `module not found` errors ([#9963](https://github.com/facebook/jest/pull/9963))

### Chore & Maintenance

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/stackTrace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('Stack Trace', () => {

// Make sure we show Jest's jest-resolve as part of the stack trace
expect(stderr).toMatch(
/Cannot find module 'this-module-does-not-exist' from 'testError.test\.js'/,
/Cannot find module 'this-module-does-not-exist' from '__tests__\/testError\.test\.js'/,
);

expect(stderr).toMatch(
Expand Down
2 changes: 1 addition & 1 deletion e2e/resolve/__tests__/resolve.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ test('should throw module not found error if the module cannot be found', () =>
expect(() => require('Test8')).toThrow(
expect.objectContaining({
code: 'MODULE_NOT_FOUND',
message: "Cannot find module 'Test8' from 'resolve.test.js'",
message: "Cannot find module 'Test8' from '__tests__/resolve.test.js'",
}),
);
});
4 changes: 2 additions & 2 deletions packages/jest-resolve/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ class Resolver {
// 5. Throw an error if the module could not be found. `resolve.sync` only
// produces an error based on the dirname but we have the actual current
// module name available.
const relativePath = path.relative(dirname, from);
const relativePath = path.relative(this._options.rootDir, from) || '.';

throw new ModuleNotFoundError(
`Cannot find module '${moduleName}' from '${relativePath || '.'}'`,
`Cannot find module '${moduleName}' from '${relativePath}'`,
moduleName,
);
}
Expand Down