Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use default cwd even if config contains a cwd property #7923

Merged
merged 1 commit into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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