Skip to content

Commit 7b2dd01

Browse files
committed
test(preset): fixes tests, doc and cli for presets
1 parent ec78757 commit 7b2dd01

4 files changed

Lines changed: 70 additions & 9 deletions

File tree

docs/user/config/index.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,18 @@ module.exports = {
5454

5555
Any preset can also be used with other options.
5656
If you're already using another preset, you might want only some specific settings from the chosen `ts-jest` preset.
57-
In this case you'll need to use the JavaScript version of Jest config:
57+
In this case you'll need to use the JavaScript version of Jest config (comment/uncomment according to your use-case):
5858

5959
```js
6060
// jest.config.js
61-
const tsJestPresets = require('ts-jest/presets');
62-
63-
const preset = tsJestPresets.defaults
64-
// const preset = tsJestPresets.jsWithTs
65-
// const preset = tsJestPresets.jsWithBabel
61+
const { defaults: tsjPreset } = require('ts-jest/presets');
62+
// const { jsWithTs: tsjPreset } = require('ts-jest/presets');
63+
// const { jsWithBabel: tsjPreset } = require('ts-jest/presets');
6664

6765
module.exports = {
6866
// [...]
6967
transform: {
70-
...preset.transform,
68+
...tsjPreset.transform,
7169
// [...]
7270
}
7371
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`test-helpers 1`] = `
4+
× jest --no-cache
5+
↳ exit code: 1
6+
===[ STDOUT ]===================================================================
7+
8+
===[ STDERR ]===================================================================
9+
PASS ./pass.spec.ts
10+
FAIL ./fail.spec.ts
11+
● Test suite failed to run
12+
13+
TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option):
14+
fail.spec.ts:7:10 - error TS2554: Expected 0 arguments, but got 1.
15+
16+
7 expect(mocked(foo)('hello')).toBeUndefined()
17+
~~~~~~~~~~~~~~~~~~~~
18+
fail.spec.ts:9:46 - error TS2345: Argument of type '42' is not assignable to parameter of type 'string'.
19+
20+
9 expect(mocked(bar, true).dummy.deep.deeper(42)).toBeUndefined()
21+
~~
22+
23+
ts-jest[root] (WARN) The \`mocked\` helper has been moved to \`ts-jest/utils\`. Use \`import { mocked } from 'ts-jest/utils'\` instead.
24+
PASS ./deprecated.spec.ts
25+
26+
Test Suites: 1 failed, 2 passed, 3 total
27+
Tests: 3 passed, 3 total
28+
Snapshots: 0 total
29+
Time: XXs
30+
Ran all test suites.
31+
================================================================================
32+
`;
33+
34+
exports[`with esModuleInterop set to false 1`] = `
35+
× jest --no-cache
36+
↳ exit code: 1
37+
===[ STDOUT ]===================================================================
38+
39+
===[ STDERR ]===================================================================
40+
PASS ./pass.spec.ts
41+
FAIL ./fail.spec.ts
42+
● Test suite failed to run
43+
44+
TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option):
45+
fail.spec.ts:7:10 - error TS2554: Expected 0 arguments, but got 1.
46+
47+
7 expect(mocked(foo)('hello')).toBeUndefined()
48+
~~~~~~~~~~~~~~~~~~~~
49+
fail.spec.ts:9:46 - error TS2345: Argument of type '42' is not assignable to parameter of type 'string'.
50+
51+
9 expect(mocked(bar, true).dummy.deep.deeper(42)).toBeUndefined()
52+
~~
53+
54+
ts-jest[root] (WARN) The \`mocked\` helper has been moved to \`ts-jest/utils\`. Use \`import { mocked } from 'ts-jest/utils'\` instead.
55+
PASS ./deprecated.spec.ts
56+
57+
Test Suites: 1 failed, 2 passed, 3 total
58+
Tests: 3 passed, 3 total
59+
Snapshots: 0 total
60+
Time: XXs
61+
Ran all test suites.
62+
================================================================================
63+
`;

src/cli/cli.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Jest configuration written to "${normalize('/foo/bar/jest.config.foo.js')}".
154154
expect(fs.writeFileSync.mock.calls).toEqual([
155155
[
156156
normalize('/foo/bar/jest.config.foo.js'),
157-
`const tsjPreset = require('ts-jest/presets/js-with-ts');
157+
`const { jsWithTs: tsjPreset } = require('ts-jest/presets');
158158
159159
module.exports = {
160160
...tsjPreset,

src/cli/helpers/presets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const definePreset = (fullName: string): TsJestPresetDescriptor => ({
3838
return require(`../../../${fullName.replace(/^ts-jest\//, '')}/jest-preset`)
3939
},
4040
jsImport(varName = 'tsjPreset') {
41-
return `const ${varName} = require('${this.fullName}')`
41+
return `const { ${this.jsVarName}: ${varName} } = require('ts-jest/presets')`
4242
},
4343
get isDefault() {
4444
return fullName === JestPresetNames.default

0 commit comments

Comments
 (0)