Skip to content

Commit

Permalink
use default cwd even if config contains a cwd property (#7923)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeysal authored Mar 26, 2019
1 parent 54ce3f3 commit 831085c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- `[jest-core]` Fix ability to transform dependencies required from globalSetup script [#8143](https://github.com/facebook/jest/pull/8143)
- `[@jest/reporters]` Fix Cannot read property converageData of null ([#8168](https://github.com/facebook/jest/pull/8168))
- `[jest-worker]` `JEST_WORKER_ID` starts at 1 ([#8205](https://github.com/facebook/jest/pull/8205))
- `[jest-config]` Use default cwd even if config contains a cwd property ([#7923](https://github.com/facebook/jest/pull/7923))

### Chore & Maintenance

Expand Down
1 change: 0 additions & 1 deletion packages/jest-config/src/Defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const defaultOptions: Config.DefaultOptions = {
coveragePathIgnorePatterns: [NODE_MODULES_REGEXP],
coverageReporters: ['json', 'text', 'lcov', 'clover'],
coverageThreshold: null,
cwd: process.cwd(),
dependencyExtractor: null,
errorOnDeprecated: false,
expand: false,
Expand Down
2 changes: 0 additions & 2 deletions packages/jest-config/src/ValidConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ const initialOptions: Config.InitialOptions = {
statements: 100,
},
},
// @ts-ignore: Missing from initial options... https://github.com/facebook/jest/pull/7923
cwd: '/root',
dependencyExtractor: '<rootDir>/dependencyExtractor.js',
displayName: 'project-name',
errorOnDeprecated: false,
Expand Down
20 changes: 20 additions & 0 deletions packages/jest-config/src/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,26 @@ describe('moduleFileExtensions', () => {
});
});

describe('cwd', () => {
it('is set to process.cwd', () => {
const {options} = normalize({rootDir: '/root/'}, {});
expect(options.cwd).toBe(process.cwd());
});

it('is not lost if the config has its own cwd property', () => {
console.warn.mockImplementation(() => {});
const {options} = normalize(
{
rootDir: '/root/',
cwd: '/tmp/config-sets-cwd-itself',
},
{},
);
expect(options.cwd).toBe(process.cwd());
expect(console.warn).toHaveBeenCalled();
});
});

describe('Defaults', () => {
it('should be accepted by normalize', () => {
normalize({...Defaults, rootDir: '/root'}, {});
Expand Down
14 changes: 7 additions & 7 deletions packages/jest-config/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,6 @@ export default function normalize(
...DEFAULT_CONFIG,
} as unknown) as AllOptions;

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 Expand Up @@ -827,6 +820,13 @@ export default function normalize(
return newOptions;
}, newOptions);

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

newOptions.nonFlagArgs = argv._;
newOptions.testPathPattern = buildTestPathPattern(argv);
newOptions.json = !!argv.json;
Expand Down
1 change: 0 additions & 1 deletion packages/jest-types/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export type DefaultOptions = {
}
| null
| undefined;
cwd: Path;
dependencyExtractor: string | null | undefined;
errorOnDeprecated: boolean;
expand: boolean;
Expand Down

0 comments on commit 831085c

Please sign in to comment.