Skip to content

Commit 1d67101

Browse files
committedFeb 14, 2019
fix: cli test
1 parent d0f2231 commit 1d67101

File tree

4 files changed

+17
-34
lines changed

4 files changed

+17
-34
lines changed
 

‎src/cli/cli.spec.ts

+12-15
Original file line numberDiff line numberDiff line change
@@ -214,20 +214,6 @@ Jest configuration written to "${normalize('/foo/bar/package.json')}".
214214
"transform": {
215215
"^.+\\\\.[tj]sx?$": "ts-jest"
216216
},
217-
"testMatch": [
218-
"**/__tests__/**/*.js?(x)",
219-
"**/?(*.)+(spec|test).js?(x)",
220-
"**/__tests__/**/*.ts?(x)",
221-
"**/?(*.)+(spec|test).ts?(x)"
222-
],
223-
"moduleFileExtensions": [
224-
"js",
225-
"json",
226-
"jsx",
227-
"node",
228-
"ts",
229-
"tsx"
230-
],
231217
"globals": {
232218
"ts-jest": {
233219
"tsconfig": "tsconfig.test.json",
@@ -387,7 +373,7 @@ Migrated Jest configuration:
387373
() => ({
388374
jest: {
389375
globals: { __TS_CONFIG__: { target: 'es6' } },
390-
moduleFileExtensions: ['js', 'json', 'tsx', 'jsx', 'node', 'ts'],
376+
moduleFileExtensions: ['ts', 'tsx', 'js'],
391377
testMatch: [
392378
'**/__tests__/**/*.js?(x)',
393379
'**/?(*.)+(spec|test).js?(x)',
@@ -408,6 +394,17 @@ Migrated Jest configuration:
408394
}
409395
}
410396
},
397+
\\"moduleFileExtensions\\": [
398+
\\"js\\",
399+
\\"ts\\",
400+
\\"tsx\\"
401+
],
402+
\\"testMatch\\": [
403+
\\"**/?(*.)+(spec|test).js?(x)\\",
404+
\\"**/?(*.)+(spec|test).ts?(x)\\",
405+
\\"**/__tests__/**/*.js?(x)\\",
406+
\\"**/__tests__/**/*.ts?(x)\\"
407+
],
411408
\\"preset\\": \\"ts-jest\\"
412409
}
413410
"

‎src/cli/config/init.ts

-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ export const run: CliCommand = async (args: Arguments /* , logger: Logger */) =>
103103
content.push(` },`)
104104
content.push(` },`)
105105
}
106-
107106
content.push('};')
108107

109108
// join all together

‎src/config/create-jest-preset.spec.ts

-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { createJestPreset } from './create-jest-preset'
22

33
it('should return correct defaults when allowJs is false or not set', () => {
44
const withoutJs = {
5-
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'],
6-
testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)'],
75
transform: {
86
'^.+\\.tsx?$': 'ts-jest',
97
},
@@ -14,8 +12,6 @@ it('should return correct defaults when allowJs is false or not set', () => {
1412

1513
it('should return correct defaults when allowJs is true', () => {
1614
expect(createJestPreset({ allowJs: true })).toEqual({
17-
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'],
18-
testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)'],
1915
transform: {
2016
'^.+\\.[tj]sx?$': 'ts-jest',
2117
},

‎src/config/create-jest-preset.ts

+5-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
import * as TJestConfigPkg from 'jest-config'
2-
31
import { rootLogger } from '../util/logger'
42

5-
import { getJestConfigPkg } from './jest-config-resolver'
6-
73
const logger = rootLogger.child({ namespace: 'jest-preset' })
84

9-
const jestConfigPkg: typeof TJestConfigPkg = getJestConfigPkg(logger)
10-
11-
const defaults = jestConfigPkg.defaults
12-
135
export interface TsJestPresets {
146
transform: Record<string, string>
15-
testMatch: string[] | undefined
16-
moduleFileExtensions: string[] | undefined
7+
testMatch?: string[]
8+
moduleFileExtensions?: string[]
179
}
1810

1911
export interface CreateJestPresetOptions {
@@ -22,16 +14,15 @@ export interface CreateJestPresetOptions {
2214

2315
export function createJestPreset(
2416
{ allowJs = false }: CreateJestPresetOptions = {},
25-
from?: jest.InitialOptions,
17+
from: jest.InitialOptions = {},
2618
): TsJestPresets {
2719
logger.debug({ allowJs }, 'creating jest presets', allowJs ? 'handling' : 'not handling', 'JavaScript files')
28-
from = { ...defaults, ...from }
2920
return {
3021
transform: {
3122
...from.transform,
3223
[allowJs ? '^.+\\.[tj]sx?$' : '^.+\\.tsx?$']: 'ts-jest',
3324
},
34-
testMatch: from.testMatch || undefined,
35-
moduleFileExtensions: from.moduleFileExtensions || undefined,
25+
...(from.testMatch ? { testMatch: from.testMatch } : undefined),
26+
...(from.moduleFileExtensions ? { moduleFileExtensions: from.moduleFileExtensions } : undefined),
3627
}
3728
}

0 commit comments

Comments
 (0)
Please sign in to comment.