Skip to content

Commit 0708daf

Browse files
authored
fix(jest-cli): use correct filename to override config (#10337)
1 parent 104a571 commit 0708daf

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Fixes
66

7+
- `[jest-cli]` Use correct file name to override existing jest config on init ([#10337](https://github.com/facebook/jest/pull/10337))
8+
79
### Chore & Maintenance
810

911
### Performance

packages/jest-cli/src/init/__tests__/init.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,10 @@ describe('init', () => {
175175

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

178+
const jestConfigFileName = fs.writeFileSync.mock.calls[0][0];
178179
const writtenJestConfig = fs.writeFileSync.mock.calls[0][1];
179180

181+
expect(jestConfigFileName).toBe(`jest.config.${extension}`);
180182
expect(writtenJestConfig).toBeDefined();
181183
});
182184

packages/jest-cli/src/init/index.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,21 @@ export default async (
6161
hasJestProperty = true;
6262
}
6363

64-
const existingJestConfigPath = JEST_CONFIG_EXT_ORDER.find(ext =>
64+
const existingJestConfigExt = JEST_CONFIG_EXT_ORDER.find(ext =>
6565
fs.existsSync(path.join(rootDir, getConfigFilename(ext))),
6666
);
67-
const jestConfigPath =
68-
existingJestConfigPath ||
69-
path.join(
70-
rootDir,
71-
getConfigFilename(
72-
projectPackageJson.type === 'module'
73-
? JEST_CONFIG_EXT_MJS
74-
: JEST_CONFIG_EXT_JS,
75-
),
76-
);
77-
78-
if (hasJestProperty || existingJestConfigPath) {
67+
const jestConfigPath = existingJestConfigExt
68+
? getConfigFilename(existingJestConfigExt)
69+
: path.join(
70+
rootDir,
71+
getConfigFilename(
72+
projectPackageJson.type === 'module'
73+
? JEST_CONFIG_EXT_MJS
74+
: JEST_CONFIG_EXT_JS,
75+
),
76+
);
77+
78+
if (hasJestProperty || existingJestConfigExt) {
7979
const result: {continue: boolean} = await prompts({
8080
initial: true,
8181
message:

0 commit comments

Comments
 (0)