Skip to content

Commit

Permalink
fix(jest-cli): use correct filename to override config (#10337)
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s authored Jul 31, 2020
1 parent 104a571 commit 0708daf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 0708daf

Please sign in to comment.