diff --git a/src/cli/cli.spec.ts b/src/cli/cli.spec.ts index 2938ab81f1..e5388a2038 100644 --- a/src/cli/cli.spec.ts +++ b/src/cli/cli.spec.ts @@ -214,20 +214,6 @@ Jest configuration written to "${normalize('/foo/bar/package.json')}". "transform": { "^.+\\\\.[tj]sx?$": "ts-jest" }, - "testMatch": [ - "**/__tests__/**/*.js?(x)", - "**/?(*.)+(spec|test).js?(x)", - "**/__tests__/**/*.ts?(x)", - "**/?(*.)+(spec|test).ts?(x)" - ], - "moduleFileExtensions": [ - "js", - "json", - "jsx", - "node", - "ts", - "tsx" - ], "globals": { "ts-jest": { "tsconfig": "tsconfig.test.json", @@ -387,7 +373,7 @@ Migrated Jest configuration: () => ({ jest: { globals: { __TS_CONFIG__: { target: 'es6' } }, - moduleFileExtensions: ['js', 'json', 'tsx', 'jsx', 'node', 'ts'], + moduleFileExtensions: ['ts', 'tsx', 'js'], testMatch: [ '**/__tests__/**/*.js?(x)', '**/?(*.)+(spec|test).js?(x)', @@ -408,6 +394,17 @@ Migrated Jest configuration: } } }, + \\"moduleFileExtensions\\": [ + \\"js\\", + \\"ts\\", + \\"tsx\\" + ], + \\"testMatch\\": [ + \\"**/?(*.)+(spec|test).js?(x)\\", + \\"**/?(*.)+(spec|test).ts?(x)\\", + \\"**/__tests__/**/*.js?(x)\\", + \\"**/__tests__/**/*.ts?(x)\\" + ], \\"preset\\": \\"ts-jest\\" } " diff --git a/src/cli/config/init.ts b/src/cli/config/init.ts index e295cab65b..410c76f75b 100644 --- a/src/cli/config/init.ts +++ b/src/cli/config/init.ts @@ -103,7 +103,6 @@ export const run: CliCommand = async (args: Arguments /* , logger: Logger */) => content.push(` },`) content.push(` },`) } - content.push('};') // join all together diff --git a/src/config/create-jest-preset.spec.ts b/src/config/create-jest-preset.spec.ts index 3347bb2f3d..cc67677e8a 100644 --- a/src/config/create-jest-preset.spec.ts +++ b/src/config/create-jest-preset.spec.ts @@ -2,8 +2,6 @@ import { createJestPreset } from './create-jest-preset' it('should return correct defaults when allowJs is false or not set', () => { const withoutJs = { - moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'], - testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)'], transform: { '^.+\\.tsx?$': 'ts-jest', }, @@ -14,8 +12,6 @@ it('should return correct defaults when allowJs is false or not set', () => { it('should return correct defaults when allowJs is true', () => { expect(createJestPreset({ allowJs: true })).toEqual({ - moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'], - testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)'], transform: { '^.+\\.[tj]sx?$': 'ts-jest', }, diff --git a/src/config/create-jest-preset.ts b/src/config/create-jest-preset.ts index 5f82022005..1d63815e6e 100644 --- a/src/config/create-jest-preset.ts +++ b/src/config/create-jest-preset.ts @@ -1,19 +1,11 @@ -import * as TJestConfigPkg from 'jest-config' - import { rootLogger } from '../util/logger' -import { getJestConfigPkg } from './jest-config-resolver' - const logger = rootLogger.child({ namespace: 'jest-preset' }) -const jestConfigPkg: typeof TJestConfigPkg = getJestConfigPkg(logger) - -const defaults = jestConfigPkg.defaults - export interface TsJestPresets { transform: Record - testMatch: string[] | undefined - moduleFileExtensions: string[] | undefined + testMatch?: string[] + moduleFileExtensions?: string[] } export interface CreateJestPresetOptions { @@ -22,16 +14,15 @@ export interface CreateJestPresetOptions { export function createJestPreset( { allowJs = false }: CreateJestPresetOptions = {}, - from?: jest.InitialOptions, + from: jest.InitialOptions = {}, ): TsJestPresets { logger.debug({ allowJs }, 'creating jest presets', allowJs ? 'handling' : 'not handling', 'JavaScript files') - from = { ...defaults, ...from } return { transform: { ...from.transform, [allowJs ? '^.+\\.[tj]sx?$' : '^.+\\.tsx?$']: 'ts-jest', }, - testMatch: from.testMatch || undefined, - moduleFileExtensions: from.moduleFileExtensions || undefined, + ...(from.testMatch ? { testMatch: from.testMatch } : undefined), + ...(from.moduleFileExtensions ? { moduleFileExtensions: from.moduleFileExtensions } : undefined), } }