Skip to content

Commit b0464e9

Browse files
authored
refactor(presets): simplify create presets codes (#1911)
1 parent b1dbcca commit b0464e9

25 files changed

+147
-159
lines changed

e2e/__cases__/module-kinds/ts-jest-tools.spec.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// preset and utils should work all the time
2+
import * as presets from 'ts-jest/presets'
3+
4+
test('presets', () => {
5+
const presetKeys = ['transform']
6+
expect(presets.defaults).toEqual(require('ts-jest/dist/presets').defaults)
7+
expect(Object.keys(presets.defaults)).toEqual(presetKeys)
8+
expect(presets.jsWithBabel).toEqual(require('ts-jest/dist/presets').jsWithBabel)
9+
expect(Object.keys(presets.jsWithBabel)).toEqual(presetKeys)
10+
expect(presets.jsWithTs).toEqual(require('ts-jest/dist/presets').jsWithTs)
11+
expect(Object.keys(presets.jsWithTs)).toEqual(presetKeys)
12+
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as utils from 'ts-jest/utils'
2+
3+
test('utils', () => {
4+
expect(Object.keys(utils)).toEqual(['mocked', 'createJestPreset', 'pathsToModuleNameMapper'])
5+
expect(typeof utils.mocked).toBe('function')
6+
expect(typeof utils.createJestPreset).toBe('function')
7+
expect(typeof utils.pathsToModuleNameMapper).toBe('function')
8+
})

e2e/__tests__/__snapshots__/logger.test.ts.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exports[`ts-jest logging TS_JEST_LOG should pass and create log file when using template "default" 1`] = `
44
Array [
5+
"[level:20] creating jest presets not handling JavaScript files",
56
"[level:20] creating jest presets not handling JavaScript files",
67
"[level:20] creating Importer singleton",
78
"[level:20] creating jest presets not handling JavaScript files",
@@ -39,6 +40,7 @@ Array [
3940
4041
exports[`ts-jest logging TS_JEST_LOG should pass and create log file when using template "with-babel-7" 1`] = `
4142
Array [
43+
"[level:20] creating jest presets not handling JavaScript files",
4244
"[level:20] creating jest presets not handling JavaScript files",
4345
"[level:20] creating Importer singleton",
4446
"[level:20] creating jest presets not handling JavaScript files",
@@ -82,6 +84,7 @@ Array [
8284
8385
exports[`ts-jest logging TS_JEST_LOG should pass and create log file when using template "with-babel-7-string-config" 1`] = `
8486
Array [
87+
"[level:20] creating jest presets not handling JavaScript files",
8588
"[level:20] creating jest presets not handling JavaScript files",
8689
"[level:20] creating Importer singleton",
8790
"[level:20] creating jest presets not handling JavaScript files",

e2e/__tests__/module-kinds/__snapshots__/amd.test.ts.snap

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ exports[`run with options: {"module":"amd","allowSyntheticDefaultImports":false}
77
88
===[ STDERR ]===================================================================
99
ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting \`esModuleInterop\` to \`true\` in your TypeScript configuration file (usually \`tsconfig.json\`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information.
10-
PASS ./ts-jest-tools.spec.ts
1110
PASS ./import-legacy.spec.ts
1211
PASS ./import-star.spec.ts
1312
ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"<cwd>/lib"' can only be default-imported using the 'esModuleInterop' flag
@@ -37,8 +36,8 @@ exports[`run with options: {"module":"amd","allowSyntheticDefaultImports":false}
3736
3837
at Object.<anonymous> (import-default.spec.ts:4:22)
3938
40-
Test Suites: 1 failed, 3 passed, 4 total
41-
Tests: 1 failed, 4 passed, 5 total
39+
Test Suites: 1 failed, 2 passed, 3 total
40+
Tests: 1 failed, 2 passed, 3 total
4241
Snapshots: 0 total
4342
Time: XXs
4443
Ran all test suites.
@@ -51,7 +50,6 @@ exports[`run with options: {"module":"amd","allowSyntheticDefaultImports":true}
5150
===[ STDOUT ]===================================================================
5251
5352
===[ STDERR ]===================================================================
54-
PASS ./ts-jest-tools.spec.ts
5553
PASS ./import-legacy.spec.ts
5654
PASS ./import-star.spec.ts
5755
FAIL ./import-default.spec.ts
@@ -72,8 +70,8 @@ exports[`run with options: {"module":"amd","allowSyntheticDefaultImports":true}
7270
7371
at Object.<anonymous> (import-default.spec.ts:4:22)
7472
75-
Test Suites: 1 failed, 3 passed, 4 total
76-
Tests: 1 failed, 4 passed, 5 total
73+
Test Suites: 1 failed, 2 passed, 3 total
74+
Tests: 1 failed, 2 passed, 3 total
7775
Snapshots: 0 total
7876
Time: XXs
7977
Ran all test suites.
@@ -87,7 +85,6 @@ exports[`run with options: {"module":"amd","esModuleInterop":false} 1`] = `
8785
8886
===[ STDERR ]===================================================================
8987
ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting \`esModuleInterop\` to \`true\` in your TypeScript configuration file (usually \`tsconfig.json\`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information.
90-
PASS ./ts-jest-tools.spec.ts
9188
PASS ./import-legacy.spec.ts
9289
PASS ./import-star.spec.ts
9390
FAIL ./import-default.spec.ts
@@ -108,8 +105,8 @@ exports[`run with options: {"module":"amd","esModuleInterop":false} 1`] = `
108105
109106
at Object.<anonymous> (import-default.spec.ts:4:22)
110107
111-
Test Suites: 1 failed, 3 passed, 4 total
112-
Tests: 1 failed, 4 passed, 5 total
108+
Test Suites: 1 failed, 2 passed, 3 total
109+
Tests: 1 failed, 2 passed, 3 total
113110
Snapshots: 0 total
114111
Time: XXs
115112
Ran all test suites.
@@ -122,7 +119,6 @@ exports[`run with options: {"module":"amd","esModuleInterop":true} 1`] = `
122119
===[ STDOUT ]===================================================================
123120
124121
===[ STDERR ]===================================================================
125-
PASS ./ts-jest-tools.spec.ts
126122
PASS ./import-legacy.spec.ts
127123
ts-jest[ts-compiler] (WARN) import-star.spec.ts:5:10 - error TS2349: This expression is not callable.
128124
Type 'typeof lib' has no call signatures.
@@ -154,8 +150,8 @@ exports[`run with options: {"module":"amd","esModuleInterop":true} 1`] = `
154150
155151
PASS ./import-default.spec.ts
156152
157-
Test Suites: 1 failed, 3 passed, 4 total
158-
Tests: 1 failed, 4 passed, 5 total
153+
Test Suites: 1 failed, 2 passed, 3 total
154+
Tests: 1 failed, 2 passed, 3 total
159155
Snapshots: 0 total
160156
Time: XXs
161157
Ran all test suites.
@@ -169,7 +165,6 @@ exports[`run with options: {"module":"amd"} 1`] = `
169165
170166
===[ STDERR ]===================================================================
171167
ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting \`esModuleInterop\` to \`true\` in your TypeScript configuration file (usually \`tsconfig.json\`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information.
172-
PASS ./ts-jest-tools.spec.ts
173168
PASS ./import-legacy.spec.ts
174169
PASS ./import-star.spec.ts
175170
FAIL ./import-default.spec.ts
@@ -190,8 +185,8 @@ exports[`run with options: {"module":"amd"} 1`] = `
190185
191186
at Object.<anonymous> (import-default.spec.ts:4:22)
192187
193-
Test Suites: 1 failed, 3 passed, 4 total
194-
Tests: 1 failed, 4 passed, 5 total
188+
Test Suites: 1 failed, 2 passed, 3 total
189+
Tests: 1 failed, 2 passed, 3 total
195190
Snapshots: 0 total
196191
Time: XXs
197192
Ran all test suites.

e2e/__tests__/module-kinds/__snapshots__/commonjs.test.ts.snap

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ exports[`run with options: {"module":"commonjs","allowSyntheticDefaultImports":f
66
===[ STDOUT ]===================================================================
77
88
===[ STDERR ]===================================================================
9-
PASS ./ts-jest-tools.spec.ts
109
PASS ./import-legacy.spec.ts
1110
PASS ./import-star.spec.ts
1211
ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"<cwd>/lib"' can only be default-imported using the 'esModuleInterop' flag
@@ -36,8 +35,8 @@ exports[`run with options: {"module":"commonjs","allowSyntheticDefaultImports":f
3635
3736
at Object.<anonymous> (import-default.spec.ts:4:22)
3837
39-
Test Suites: 1 failed, 3 passed, 4 total
40-
Tests: 1 failed, 4 passed, 5 total
38+
Test Suites: 1 failed, 2 passed, 3 total
39+
Tests: 1 failed, 2 passed, 3 total
4140
Snapshots: 0 total
4241
Time: XXs
4342
Ran all test suites.
@@ -50,7 +49,6 @@ exports[`run with options: {"module":"commonjs","allowSyntheticDefaultImports":t
5049
===[ STDOUT ]===================================================================
5150
5251
===[ STDERR ]===================================================================
53-
PASS ./ts-jest-tools.spec.ts
5452
PASS ./import-legacy.spec.ts
5553
PASS ./import-star.spec.ts
5654
FAIL ./import-default.spec.ts
@@ -71,8 +69,8 @@ exports[`run with options: {"module":"commonjs","allowSyntheticDefaultImports":t
7169
7270
at Object.<anonymous> (import-default.spec.ts:4:22)
7371
74-
Test Suites: 1 failed, 3 passed, 4 total
75-
Tests: 1 failed, 4 passed, 5 total
72+
Test Suites: 1 failed, 2 passed, 3 total
73+
Tests: 1 failed, 2 passed, 3 total
7674
Snapshots: 0 total
7775
Time: XXs
7876
Ran all test suites.
@@ -85,7 +83,6 @@ exports[`run with options: {"module":"commonjs","esModuleInterop":false} 1`] = `
8583
===[ STDOUT ]===================================================================
8684
8785
===[ STDERR ]===================================================================
88-
PASS ./ts-jest-tools.spec.ts
8986
PASS ./import-legacy.spec.ts
9087
PASS ./import-star.spec.ts
9188
ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"<cwd>/lib"' can only be default-imported using the 'esModuleInterop' flag
@@ -115,8 +112,8 @@ exports[`run with options: {"module":"commonjs","esModuleInterop":false} 1`] = `
115112
116113
at Object.<anonymous> (import-default.spec.ts:4:22)
117114
118-
Test Suites: 1 failed, 3 passed, 4 total
119-
Tests: 1 failed, 4 passed, 5 total
115+
Test Suites: 1 failed, 2 passed, 3 total
116+
Tests: 1 failed, 2 passed, 3 total
120117
Snapshots: 0 total
121118
Time: XXs
122119
Ran all test suites.
@@ -129,7 +126,6 @@ exports[`run with options: {"module":"commonjs","esModuleInterop":true} 1`] = `
129126
===[ STDOUT ]===================================================================
130127
131128
===[ STDERR ]===================================================================
132-
PASS ./ts-jest-tools.spec.ts
133129
PASS ./import-legacy.spec.ts
134130
ts-jest[ts-compiler] (WARN) import-star.spec.ts:5:10 - error TS2349: This expression is not callable.
135131
Type 'typeof lib' has no call signatures.
@@ -161,8 +157,8 @@ exports[`run with options: {"module":"commonjs","esModuleInterop":true} 1`] = `
161157
162158
PASS ./import-default.spec.ts
163159
164-
Test Suites: 1 failed, 3 passed, 4 total
165-
Tests: 1 failed, 4 passed, 5 total
160+
Test Suites: 1 failed, 2 passed, 3 total
161+
Tests: 1 failed, 2 passed, 3 total
166162
Snapshots: 0 total
167163
Time: XXs
168164
Ran all test suites.
@@ -175,7 +171,6 @@ exports[`run with options: {"module":"commonjs"} 1`] = `
175171
===[ STDOUT ]===================================================================
176172
177173
===[ STDERR ]===================================================================
178-
PASS ./ts-jest-tools.spec.ts
179174
PASS ./import-legacy.spec.ts
180175
PASS ./import-star.spec.ts
181176
ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"<cwd>/lib"' can only be default-imported using the 'esModuleInterop' flag
@@ -205,8 +200,8 @@ exports[`run with options: {"module":"commonjs"} 1`] = `
205200
206201
at Object.<anonymous> (import-default.spec.ts:4:22)
207202
208-
Test Suites: 1 failed, 3 passed, 4 total
209-
Tests: 1 failed, 4 passed, 5 total
203+
Test Suites: 1 failed, 2 passed, 3 total
204+
Tests: 1 failed, 2 passed, 3 total
210205
Snapshots: 0 total
211206
Time: XXs
212207
Ran all test suites.

e2e/__tests__/module-kinds/__snapshots__/es2015.test.ts.snap

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ exports[`run with options: {"module":"es2015","allowSyntheticDefaultImports":fal
77
88
===[ STDERR ]===================================================================
99
ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting \`esModuleInterop\` to \`true\` in your TypeScript configuration file (usually \`tsconfig.json\`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information.
10-
PASS ./ts-jest-tools.spec.ts
1110
PASS ./import-legacy.spec.ts
1211
PASS ./import-star.spec.ts
1312
ts-jest[ts-compiler] (WARN) import-default.spec.ts:1:8 - error TS1259: Module '"<cwd>/lib"' can only be default-imported using the 'esModuleInterop' flag
@@ -37,8 +36,8 @@ exports[`run with options: {"module":"es2015","allowSyntheticDefaultImports":fal
3736
3837
at Object.<anonymous> (import-default.spec.ts:4:22)
3938
40-
Test Suites: 1 failed, 3 passed, 4 total
41-
Tests: 1 failed, 4 passed, 5 total
39+
Test Suites: 1 failed, 2 passed, 3 total
40+
Tests: 1 failed, 2 passed, 3 total
4241
Snapshots: 0 total
4342
Time: XXs
4443
Ran all test suites.
@@ -51,7 +50,6 @@ exports[`run with options: {"module":"es2015","allowSyntheticDefaultImports":tru
5150
===[ STDOUT ]===================================================================
5251
5352
===[ STDERR ]===================================================================
54-
PASS ./ts-jest-tools.spec.ts
5553
PASS ./import-legacy.spec.ts
5654
PASS ./import-star.spec.ts
5755
FAIL ./import-default.spec.ts
@@ -72,8 +70,8 @@ exports[`run with options: {"module":"es2015","allowSyntheticDefaultImports":tru
7270
7371
at Object.<anonymous> (import-default.spec.ts:4:22)
7472
75-
Test Suites: 1 failed, 3 passed, 4 total
76-
Tests: 1 failed, 4 passed, 5 total
73+
Test Suites: 1 failed, 2 passed, 3 total
74+
Tests: 1 failed, 2 passed, 3 total
7775
Snapshots: 0 total
7876
Time: XXs
7977
Ran all test suites.
@@ -87,7 +85,6 @@ exports[`run with options: {"module":"es2015","esModuleInterop":false} 1`] = `
8785
8886
===[ STDERR ]===================================================================
8987
ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting \`esModuleInterop\` to \`true\` in your TypeScript configuration file (usually \`tsconfig.json\`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information.
90-
PASS ./ts-jest-tools.spec.ts
9188
PASS ./import-legacy.spec.ts
9289
PASS ./import-star.spec.ts
9390
FAIL ./import-default.spec.ts
@@ -108,8 +105,8 @@ exports[`run with options: {"module":"es2015","esModuleInterop":false} 1`] = `
108105
109106
at Object.<anonymous> (import-default.spec.ts:4:22)
110107
111-
Test Suites: 1 failed, 3 passed, 4 total
112-
Tests: 1 failed, 4 passed, 5 total
108+
Test Suites: 1 failed, 2 passed, 3 total
109+
Tests: 1 failed, 2 passed, 3 total
113110
Snapshots: 0 total
114111
Time: XXs
115112
Ran all test suites.
@@ -122,7 +119,6 @@ exports[`run with options: {"module":"es2015","esModuleInterop":true} 1`] = `
122119
===[ STDOUT ]===================================================================
123120
124121
===[ STDERR ]===================================================================
125-
PASS ./ts-jest-tools.spec.ts
126122
PASS ./import-legacy.spec.ts
127123
ts-jest[ts-compiler] (WARN) import-star.spec.ts:5:10 - error TS2349: This expression is not callable.
128124
Type 'typeof lib' has no call signatures.
@@ -154,8 +150,8 @@ exports[`run with options: {"module":"es2015","esModuleInterop":true} 1`] = `
154150
155151
PASS ./import-default.spec.ts
156152
157-
Test Suites: 1 failed, 3 passed, 4 total
158-
Tests: 1 failed, 4 passed, 5 total
153+
Test Suites: 1 failed, 2 passed, 3 total
154+
Tests: 1 failed, 2 passed, 3 total
159155
Snapshots: 0 total
160156
Time: XXs
161157
Ran all test suites.
@@ -169,7 +165,6 @@ exports[`run with options: {"module":"es2015"} 1`] = `
169165
170166
===[ STDERR ]===================================================================
171167
ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting \`esModuleInterop\` to \`true\` in your TypeScript configuration file (usually \`tsconfig.json\`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information.
172-
PASS ./ts-jest-tools.spec.ts
173168
PASS ./import-legacy.spec.ts
174169
PASS ./import-star.spec.ts
175170
FAIL ./import-default.spec.ts
@@ -190,8 +185,8 @@ exports[`run with options: {"module":"es2015"} 1`] = `
190185
191186
at Object.<anonymous> (import-default.spec.ts:4:22)
192187
193-
Test Suites: 1 failed, 3 passed, 4 total
194-
Tests: 1 failed, 4 passed, 5 total
188+
Test Suites: 1 failed, 2 passed, 3 total
189+
Tests: 1 failed, 2 passed, 3 total
195190
Snapshots: 0 total
196191
Time: XXs
197192
Ran all test suites.

0 commit comments

Comments
 (0)