Skip to content

Commit 3c325e8

Browse files
committedSep 24, 2018
fix(preset): createJestPreset fails with base and no array
If no moduleFileExtensions or testMatch is given to the createJestPreset it'd fail
1 parent e317e3b commit 3c325e8

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed
 

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

+43
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,46 @@ it('should return correct defaults when allowJs is true', () => {
3131
},
3232
})
3333
})
34+
35+
it('should be able to use a base config', () => {
36+
expect(createJestPreset(undefined, {})).toMatchInlineSnapshot(`
37+
Object {
38+
"moduleFileExtensions": Array [
39+
"js",
40+
"json",
41+
"jsx",
42+
"node",
43+
"ts",
44+
"tsx",
45+
],
46+
"testMatch": Array [
47+
"**/__tests__/**/*.js?(x)",
48+
"**/?(*.)+(spec|test).js?(x)",
49+
"**/__tests__/**/*.ts?(x)",
50+
"**/?(*.)+(spec|test).ts?(x)",
51+
],
52+
"transform": Object {
53+
"^.+\\\\.tsx?$": "ts-jest",
54+
},
55+
}
56+
`)
57+
expect(createJestPreset(undefined, { testMatch: ['foo'], moduleFileExtensions: ['bar'], transform: { foo: 'bar' } }))
58+
.toMatchInlineSnapshot(`
59+
Object {
60+
"moduleFileExtensions": Array [
61+
"bar",
62+
"ts",
63+
"tsx",
64+
],
65+
"testMatch": Array [
66+
"foo",
67+
"**/__tests__/**/*.ts?(x)",
68+
"**/?(*.)+(spec|test).ts?(x)",
69+
],
70+
"transform": Object {
71+
"^.+\\\\.tsx?$": "ts-jest",
72+
"foo": "bar",
73+
},
74+
}
75+
`)
76+
})

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

+4-6
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@ const defaults = jestConfig.defaults || {
1212
moduleFileExtensions: ['js', 'json', 'jsx', 'node'],
1313
}
1414

15-
export function createJestPreset(
16-
{ allowJs = false }: CreateJestPresetOptions = {},
17-
from: jest.InitialOptions = defaults,
18-
) {
15+
export function createJestPreset({ allowJs = false }: CreateJestPresetOptions = {}, from?: jest.InitialOptions) {
1916
logger.debug({ allowJs }, 'creating jest presets', allowJs ? 'handling' : 'not handling', 'JavaScript files')
17+
from = { ...defaults, ...from }
2018
return {
2119
transform: {
2220
...from.transform,
2321
[allowJs ? '^.+\\.[tj]sx?$' : '^.+\\.tsx?$']: 'ts-jest',
2422
},
25-
testMatch: dedup([...from.testMatch, '**/__tests__/**/*.ts?(x)', '**/?(*.)+(spec|test).ts?(x)']),
26-
moduleFileExtensions: dedup([...from.moduleFileExtensions, 'ts', 'tsx']),
23+
testMatch: dedup([...(from.testMatch || []), '**/__tests__/**/*.ts?(x)', '**/?(*.)+(spec|test).ts?(x)']),
24+
moduleFileExtensions: dedup([...(from.moduleFileExtensions || []), 'ts', 'tsx']),
2725
}
2826
}
2927

0 commit comments

Comments
 (0)
Please sign in to comment.