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 @@ -109,6 +109,7 @@
- `[jest-resolve]` Fix `isBuiltinModule` to support versions of node without `module.builtinModules` ([#7565](https://github.com/facebook/jest/pull/7565))
- `[babel-jest]` Set `cwd` to be resilient to it changing during the runtime of the tests ([#7574](https://github.com/facebook/jest/pull/7574))
- `[jest-snapshot]` Write and read snapshots from disk even if `fs` is mocked ([#7080](https://github.com/facebook/jest/pull/7080))
- `[jest-config]` Normalize `config.cwd` and `config.rootDir` using `realpath ([#7598](https://github.com/facebook/jest/pull/7598))

### Chore & Maintenance

Expand Down
3 changes: 2 additions & 1 deletion packages/jest-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"jest-util": "^23.4.0",
"jest-validate": "^23.6.0",
"micromatch": "^2.3.11",
"pretty-format": "^23.6.0"
"pretty-format": "^23.6.0",
"realpath-native": "^1.0.2"
},
"engines": {
"node": ">= 6"
Expand Down
16 changes: 16 additions & 0 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {clearLine} from 'jest-util';
import chalk from 'chalk';
import getMaxWorkers from './getMaxWorkers';
import micromatch from 'micromatch';
import {sync as realpath} from 'realpath-native';
import Resolver from 'jest-resolve';
import {replacePathSepForRegex} from 'jest-regex-util';
import {
Expand Down Expand Up @@ -288,6 +289,14 @@ const normalizeRootDir = (options: InitialOptions): InitialOptions => {
);
}
options.rootDir = path.normalize(options.rootDir);

try {
// try to resolve windows short paths, ignoring errors (permission errors, mostly)
options.rootDir = realpath(options.rootDir);
} catch (e) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it threw on CI since we have some /root/path in tests, which got a permission error

// ignored
}

return options;
};

Expand Down Expand Up @@ -442,6 +451,13 @@ export default function normalize(options: InitialOptions, argv: Argv) {
DefaultOptions & ProjectConfig & GlobalConfig,
> = (Object.assign({}, DEFAULT_CONFIG): any);

try {
// try to resolve windows short paths, ignoring errors (permission errors, mostly)
newOptions.cwd = realpath(newOptions.cwd);
} catch (e) {
// ignored
}

if (options.resolver) {
newOptions.resolver = resolve(null, {
filePath: options.resolver,
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11234,7 +11234,7 @@ readdirp@^2.0.0:
micromatch "^3.1.10"
readable-stream "^2.0.2"

realpath-native@^1.0.0:
realpath-native@^1.0.0, realpath-native@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/realpath-native/-/realpath-native-1.0.2.tgz#cd51ce089b513b45cf9b1516c82989b51ccc6560"
integrity sha512-+S3zTvVt9yTntFrBpm7TQmQ3tzpCrnA1a/y+3cUHAc9ZR6aIjG0WNLR+Rj79QpJktY+VeW/TQtFlQ1bzsehI8g==
Expand Down