Skip to content

Commit

Permalink
fix: normalize rootDir and cwd to their realpath (#7598)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Jan 10, 2019
1 parent 5f4e5cd commit 50c3852
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
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) {
// 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

0 comments on commit 50c3852

Please sign in to comment.