Skip to content

Commit 31ad0aa

Browse files
committed
fix(cli): resets testMatch if using testRegex option
Closes #756
1 parent 9f816d2 commit 31ad0aa

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/cli/cli.spec.ts

+24
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,29 @@ Migrated Jest configuration:
405405
`)
406406
})
407407

408+
it('should reset testMatch if testRegex is used', async () => {
409+
expect.assertions(1)
410+
fs.existsSync.mockImplementation(() => true)
411+
jest.mock(
412+
pkgPaths.next,
413+
() => ({
414+
jest: {
415+
testRegex: 'foo-pattern',
416+
},
417+
}),
418+
{ virtual: true },
419+
)
420+
const res = await runCli(...noOption, pkgPaths.current)
421+
expect(res.stdout).toMatchInlineSnapshot(`
422+
"{
423+
\\"testRegex\\": \\"foo-pattern\\",
424+
\\"preset\\": \\"ts-jest\\",
425+
\\"testMatch\\": null
426+
}
427+
"
428+
`)
429+
})
430+
408431
it('should normalize transform values', async () => {
409432
expect.assertions(1)
410433
fs.existsSync.mockImplementation(() => true)
@@ -434,6 +457,7 @@ Migrated Jest configuration:
434457
"
435458
`)
436459
})
460+
437461
it('should output help', async () => {
438462
const res = await runCli('help', noOption[0])
439463
expect(res).toMatchInlineSnapshot(`

src/cli/config/migrate.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ export const run: CliCommand = async (args: Arguments /*, logger: Logger*/) => {
5050
delete migratedConfig.moduleFileExtensions
5151
}
5252
}
53+
// there is a testRegex, remove our testMatch
54+
if (migratedConfig.testRegex && usesPreset) {
55+
migratedConfig.testMatch = null as any
56+
}
5357
// check the testMatch
54-
if (migratedConfig.testMatch && migratedConfig.testMatch.length && usesPreset) {
58+
else if (migratedConfig.testMatch && migratedConfig.testMatch.length && usesPreset) {
5559
const presetValue = dedupSort(presets.testMatch).join('::')
5660
const migratedValue = dedupSort(migratedConfig.testMatch).join('::')
5761
if (presetValue === migratedValue) {

0 commit comments

Comments
 (0)