Skip to content

Commit

Permalink
fix(cli): resets testMatch if using testRegex option
Browse files Browse the repository at this point in the history
Closes #756
  • Loading branch information
huafu committed Sep 24, 2018
1 parent 9f816d2 commit 31ad0aa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/cli/cli.spec.ts
Expand Up @@ -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)
Expand Down Expand Up @@ -434,6 +457,7 @@ Migrated Jest configuration:
"
`)
})

it('should output help', async () => {
const res = await runCli('help', noOption[0])
expect(res).toMatchInlineSnapshot(`
Expand Down
6 changes: 5 additions & 1 deletion src/cli/config/migrate.ts
Expand Up @@ -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) {
Expand Down

0 comments on commit 31ad0aa

Please sign in to comment.