diff --git a/CHANGELOG.md b/CHANGELOG.md index 9efb72ecf5a0..09a1d301a013 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/jest-config/package.json b/packages/jest-config/package.json index b00d0b7c52c7..1088d90fc266 100644 --- a/packages/jest-config/package.json +++ b/packages/jest-config/package.json @@ -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" diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index bf1f3bdbd329..e820158e1157 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -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 { @@ -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; }; @@ -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, diff --git a/yarn.lock b/yarn.lock index b6a123763cf5..170690cb062c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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==