diff --git a/src/cli/cli.spec.ts b/src/cli/cli.spec.ts index a30adb7412..da4164ff01 100644 --- a/src/cli/cli.spec.ts +++ b/src/cli/cli.spec.ts @@ -405,6 +405,29 @@ Migrated Jest configuration: `) }) + it('should reset testMatch if testRegex is used', async () => { + expect.assertions(1) + fs.existsSync.mockImplementation(() => true) + jest.mock( + pkgPaths.next, + () => ({ + jest: { + testRegex: 'foo-pattern', + }, + }), + { virtual: true }, + ) + const res = await runCli(...noOption, pkgPaths.current) + expect(res.stdout).toMatchInlineSnapshot(` +"{ + \\"testRegex\\": \\"foo-pattern\\", + \\"preset\\": \\"ts-jest\\", + \\"testMatch\\": null +} +" +`) + }) + it('should normalize transform values', async () => { expect.assertions(1) fs.existsSync.mockImplementation(() => true) @@ -434,6 +457,7 @@ Migrated Jest configuration: " `) }) + it('should output help', async () => { const res = await runCli('help', noOption[0]) expect(res).toMatchInlineSnapshot(` diff --git a/src/cli/config/migrate.ts b/src/cli/config/migrate.ts index f03e6d4b85..fe82846f73 100644 --- a/src/cli/config/migrate.ts +++ b/src/cli/config/migrate.ts @@ -50,8 +50,12 @@ export const run: CliCommand = async (args: Arguments /*, logger: Logger*/) => { delete migratedConfig.moduleFileExtensions } } + // there is a testRegex, remove our testMatch + if (migratedConfig.testRegex && usesPreset) { + migratedConfig.testMatch = null as any + } // check the testMatch - if (migratedConfig.testMatch && migratedConfig.testMatch.length && usesPreset) { + else if (migratedConfig.testMatch && migratedConfig.testMatch.length && usesPreset) { const presetValue = dedupSort(presets.testMatch).join('::') const migratedValue = dedupSort(migratedConfig.testMatch).join('::') if (presetValue === migratedValue) {