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

fix(jest-cli): use correct filename to override config #10337

Merged
merged 3 commits into from Jul 31, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@

### Fixes

- `[jest-cli]` Use correct file name to override existing jest config on init ([#10337](https://github.com/facebook/jest/pull/10337))

### Chore & Maintenance

### Performance
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-cli/src/init/__tests__/init.test.js
Expand Up @@ -175,8 +175,10 @@ describe('init', () => {

expect(prompts.mock.calls[0][0]).toMatchSnapshot();

const jestConfigFileName = fs.writeFileSync.mock.calls[0][0];
const writtenJestConfig = fs.writeFileSync.mock.calls[0][1];

expect(jestConfigFileName).toBe(`jest.config.${extension}`);
expect(writtenJestConfig).toBeDefined();
});

Expand Down
26 changes: 13 additions & 13 deletions packages/jest-cli/src/init/index.ts
Expand Up @@ -61,21 +61,21 @@ export default async (
hasJestProperty = true;
}

const existingJestConfigPath = JEST_CONFIG_EXT_ORDER.find(ext =>
const existingJestConfigExt = JEST_CONFIG_EXT_ORDER.find(ext =>
fs.existsSync(path.join(rootDir, getConfigFilename(ext))),
);
const jestConfigPath =
existingJestConfigPath ||
path.join(
rootDir,
getConfigFilename(
projectPackageJson.type === 'module'
? JEST_CONFIG_EXT_MJS
: JEST_CONFIG_EXT_JS,
),
);

if (hasJestProperty || existingJestConfigPath) {
const jestConfigPath = existingJestConfigExt
? getConfigFilename(existingJestConfigExt)
: path.join(
rootDir,
getConfigFilename(
projectPackageJson.type === 'module'
? JEST_CONFIG_EXT_MJS
: JEST_CONFIG_EXT_JS,
),
);

if (hasJestProperty || existingJestConfigExt) {
const result: {continue: boolean} = await prompts({
initial: true,
message:
Expand Down