Skip to content

Commit 831085c

Browse files
authored
use default cwd even if config contains a cwd property (#7923)
1 parent 54ce3f3 commit 831085c

6 files changed

Lines changed: 28 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- `[jest-core]` Fix ability to transform dependencies required from globalSetup script [#8143](https://github.com/facebook/jest/pull/8143)
2222
- `[@jest/reporters]` Fix Cannot read property converageData of null ([#8168](https://github.com/facebook/jest/pull/8168))
2323
- `[jest-worker]` `JEST_WORKER_ID` starts at 1 ([#8205](https://github.com/facebook/jest/pull/8205))
24+
- `[jest-config]` Use default cwd even if config contains a cwd property ([#7923](https://github.com/facebook/jest/pull/7923))
2425

2526
### Chore & Maintenance
2627

packages/jest-config/src/Defaults.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const defaultOptions: Config.DefaultOptions = {
2626
coveragePathIgnorePatterns: [NODE_MODULES_REGEXP],
2727
coverageReporters: ['json', 'text', 'lcov', 'clover'],
2828
coverageThreshold: null,
29-
cwd: process.cwd(),
3029
dependencyExtractor: null,
3130
errorOnDeprecated: false,
3231
expand: false,

packages/jest-config/src/ValidConfig.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ const initialOptions: Config.InitialOptions = {
3838
statements: 100,
3939
},
4040
},
41-
// @ts-ignore: Missing from initial options... https://github.com/facebook/jest/pull/7923
42-
cwd: '/root',
4341
dependencyExtractor: '<rootDir>/dependencyExtractor.js',
4442
displayName: 'project-name',
4543
errorOnDeprecated: false,

packages/jest-config/src/__tests__/normalize.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,26 @@ describe('moduleFileExtensions', () => {
15121512
});
15131513
});
15141514

1515+
describe('cwd', () => {
1516+
it('is set to process.cwd', () => {
1517+
const {options} = normalize({rootDir: '/root/'}, {});
1518+
expect(options.cwd).toBe(process.cwd());
1519+
});
1520+
1521+
it('is not lost if the config has its own cwd property', () => {
1522+
console.warn.mockImplementation(() => {});
1523+
const {options} = normalize(
1524+
{
1525+
rootDir: '/root/',
1526+
cwd: '/tmp/config-sets-cwd-itself',
1527+
},
1528+
{},
1529+
);
1530+
expect(options.cwd).toBe(process.cwd());
1531+
expect(console.warn).toHaveBeenCalled();
1532+
});
1533+
});
1534+
15151535
describe('Defaults', () => {
15161536
it('should be accepted by normalize', () => {
15171537
normalize({...Defaults, rootDir: '/root'}, {});

packages/jest-config/src/normalize.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -486,13 +486,6 @@ export default function normalize(
486486
...DEFAULT_CONFIG,
487487
} as unknown) as AllOptions;
488488

489-
try {
490-
// try to resolve windows short paths, ignoring errors (permission errors, mostly)
491-
newOptions.cwd = realpath(newOptions.cwd);
492-
} catch (e) {
493-
// ignored
494-
}
495-
496489
if (options.resolver) {
497490
newOptions.resolver = resolve(null, {
498491
filePath: options.resolver,
@@ -827,6 +820,13 @@ export default function normalize(
827820
return newOptions;
828821
}, newOptions);
829822

823+
try {
824+
// try to resolve windows short paths, ignoring errors (permission errors, mostly)
825+
newOptions.cwd = realpath(process.cwd());
826+
} catch (e) {
827+
// ignored
828+
}
829+
830830
newOptions.nonFlagArgs = argv._;
831831
newOptions.testPathPattern = buildTestPathPattern(argv);
832832
newOptions.json = !!argv.json;

packages/jest-types/src/Config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export type DefaultOptions = {
4545
}
4646
| null
4747
| undefined;
48-
cwd: Path;
4948
dependencyExtractor: string | null | undefined;
5049
errorOnDeprecated: boolean;
5150
expand: boolean;

0 commit comments

Comments
 (0)