From c9315a60aa8a93886622b27bb398c8a00f16194d Mon Sep 17 00:00:00 2001 From: sibiraj-s Date: Thu, 30 Jul 2020 19:45:33 +0530 Subject: [PATCH 1/3] fix(jest-cli): use correct filename to override config --- .../jest-cli/src/init/__tests__/init.test.js | 2 ++ packages/jest-cli/src/init/index.ts | 26 +++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/jest-cli/src/init/__tests__/init.test.js b/packages/jest-cli/src/init/__tests__/init.test.js index 74012354c51a..0824c70f43a1 100644 --- a/packages/jest-cli/src/init/__tests__/init.test.js +++ b/packages/jest-cli/src/init/__tests__/init.test.js @@ -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(); }); diff --git a/packages/jest-cli/src/init/index.ts b/packages/jest-cli/src/init/index.ts index c39ca0b68f69..707b41df12bc 100644 --- a/packages/jest-cli/src/init/index.ts +++ b/packages/jest-cli/src/init/index.ts @@ -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: From c3c66a7acae6aa41445113d9d1463920199f6000 Mon Sep 17 00:00:00 2001 From: sibiraj-s Date: Thu, 30 Jul 2020 20:17:10 +0530 Subject: [PATCH 2/3] chore: update CHNAGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 392a977ffa31..4bfdba9856aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Fixes +- `[jest-cli]` Use correct file name to override exisiting jest config on init ([#10337](https://github.com/facebook/jest/pull/10337)) + ### Chore & Maintenance ### Performance From c06139d37bf343aee5687de9c59614e8e12932ad Mon Sep 17 00:00:00 2001 From: sibiraj-s Date: Thu, 30 Jul 2020 20:49:20 +0530 Subject: [PATCH 3/3] chore: fix typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bfdba9856aa..c2f6e40f09f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Fixes -- `[jest-cli]` Use correct file name to override exisiting jest config on init ([#10337](https://github.com/facebook/jest/pull/10337)) +- `[jest-cli]` Use correct file name to override existing jest config on init ([#10337](https://github.com/facebook/jest/pull/10337)) ### Chore & Maintenance