Skip to content

Commit 3eca7dd

Browse files
SimenBcaptain-yossarian
authored andcommitted
fix: normalize rootDir and cwd to their realpath (jestjs#7598)
1 parent 57da558 commit 3eca7dd

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
- `[jest-resolve]` Fix `isBuiltinModule` to support versions of node without `module.builtinModules` ([#7565](https://github.com/facebook/jest/pull/7565))
110110
- `[babel-jest]` Set `cwd` to be resilient to it changing during the runtime of the tests ([#7574](https://github.com/facebook/jest/pull/7574))
111111
- `[jest-snapshot]` Write and read snapshots from disk even if `fs` is mocked ([#7080](https://github.com/facebook/jest/pull/7080))
112+
- `[jest-config]` Normalize `config.cwd` and `config.rootDir` using `realpath ([#7598](https://github.com/facebook/jest/pull/7598))
112113

113114
### Chore & Maintenance
114115

packages/jest-config/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"jest-util": "^23.4.0",
2222
"jest-validate": "^23.6.0",
2323
"micromatch": "^2.3.11",
24-
"pretty-format": "^23.6.0"
24+
"pretty-format": "^23.6.0",
25+
"realpath-native": "^1.0.2"
2526
},
2627
"engines": {
2728
"node": ">= 6"

packages/jest-config/src/normalize.js

+16
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {clearLine} from 'jest-util';
2525
import chalk from 'chalk';
2626
import getMaxWorkers from './getMaxWorkers';
2727
import micromatch from 'micromatch';
28+
import {sync as realpath} from 'realpath-native';
2829
import Resolver from 'jest-resolve';
2930
import {replacePathSepForRegex} from 'jest-regex-util';
3031
import {
@@ -288,6 +289,14 @@ const normalizeRootDir = (options: InitialOptions): InitialOptions => {
288289
);
289290
}
290291
options.rootDir = path.normalize(options.rootDir);
292+
293+
try {
294+
// try to resolve windows short paths, ignoring errors (permission errors, mostly)
295+
options.rootDir = realpath(options.rootDir);
296+
} catch (e) {
297+
// ignored
298+
}
299+
291300
return options;
292301
};
293302

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

454+
try {
455+
// try to resolve windows short paths, ignoring errors (permission errors, mostly)
456+
newOptions.cwd = realpath(newOptions.cwd);
457+
} catch (e) {
458+
// ignored
459+
}
460+
445461
if (options.resolver) {
446462
newOptions.resolver = resolve(null, {
447463
filePath: options.resolver,

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -11234,7 +11234,7 @@ readdirp@^2.0.0:
1123411234
micromatch "^3.1.10"
1123511235
readable-stream "^2.0.2"
1123611236

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

0 commit comments

Comments
 (0)