Skip to content

Commit 5a69bce

Browse files
authored
feat(config): add incremental option (#1418)
1 parent a0ddca7 commit 5a69bce

32 files changed

+732
-102
lines changed

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ module.exports = {
77
ecmaVersion: 2020,
88
sourceType: 'module',
99
impliedStrict: true,
10+
ecmaFeatures: {
11+
jsx: true,
12+
},
1013
},
1114
rules: {
1215
'no-console': ['error', { allow: ['warn', 'error', 'log'] }],

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<a name="25.2.1"></a>
2-
# [25.2.1](https://github.com/kulshekhar/ts-jest/compare/25.2.1...25.2.0) (2020-02-21)
2+
# [25.2.1](https://github.com/kulshekhar/ts-jest/compare/25.2.0...25.2.1) (2020-02-21)
33

44

55
### Bug Fixes

docs/user/config/compilerHost.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
title: Compiler Host option
3+
---
4+
5+
By default `ts-jest` uses TypeScript `LanguageService` API in the context of a project (yours), with full type-checking and features.
6+
But TypeScript `Program` can also be used to achieve the same behavior as `LanguageService`.
7+
That's what the `compilerHost` option (which defaults to `false`) does.
8+
9+
There are 2 types of TypeScript `Program`, one is `Incremental Program` which is only available from TypeScript 3.4
10+
and the other one is normal `Program`.
11+
12+
By default `ts-jest` uses `Incremental Program` if `compilerHost` is enabled. The priority of using TypeScript APIs in `ts-jest`
13+
as below:
14+
- Default TypeScript API is `LanguageService`.
15+
- `compilerHost` is enabled:
16+
- `incremental` is enabled (**default**): use TypeScript `Incremental Program`.
17+
- `incremental` is disabled: use TypeScript `Program`.
18+
- `isolatedModules` is enabled, use TypeScript transpile modules.
19+
20+
Here is how to enable `ts-jest` to compile using TypeScript `Program`
21+
22+
### Example
23+
24+
<div class="row"><div class="col-md-6" markdown="block">
25+
26+
```js
27+
// jest.config.js
28+
module.exports = {
29+
// [...]
30+
globals: {
31+
'ts-jest': {
32+
compilerHost: true,
33+
incremental: false,
34+
}
35+
}
36+
};
37+
```
38+
39+
</div><div class="col-md-6" markdown="block">
40+
41+
```js
42+
// OR package.json
43+
{
44+
// [...]
45+
"jest": {
46+
"globals": {
47+
"ts-jest": {
48+
"compilerHost": true,
49+
"incremental": false
50+
}
51+
}
52+
}
53+
}
54+
```
55+
56+
</div></div>
57+
58+
59+
Here is how to enable `ts-jest` to compile using TypeScript `IncrementalProgram`
60+
61+
### Example
62+
63+
<div class="row"><div class="col-md-6" markdown="block">
64+
65+
```js
66+
// jest.config.js
67+
module.exports = {
68+
// [...]
69+
globals: {
70+
'ts-jest': {
71+
compilerHost: true
72+
}
73+
}
74+
};
75+
```
76+
77+
</div><div class="col-md-6" markdown="block">
78+
79+
```js
80+
// OR package.json
81+
{
82+
// [...]
83+
"jest": {
84+
"globals": {
85+
"ts-jest": {
86+
"compilerHost": true
87+
}
88+
}
89+
}
90+
}
91+
```
92+
93+
</div></div>

docs/user/config/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ npx ts-jest config:migrate package.json
220220
[compiler]: compiler
221221
[tsConfig]: tsConfig
222222
[isolatedModules]: isolatedModules
223+
[compilerHost]: compilerHost
223224
[diagnostics]: diagnostics
224225
[babelConfig]: babelConfig
225226
[stringifyContentPathRegex]: stringifyContentPathRegex
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { g } from './main'
2+
3+
it('should pass', () => {
4+
const x: string = g(5)
5+
expect(x).toBe(5)
6+
})

e2e/__cases__/compiler-host/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const g = (v: number) => v

e2e/__cases__/composite/foo.spec.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

e2e/__cases__/composite/tsconfig.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

e2e/__helpers__/templates.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ export enum PackageSets {
66
// invalid
77
unsupportedVersion = 'with-unsupported-version',
88
}
9-
export const allValidPackageSets = [PackageSets.default, PackageSets.babel7, PackageSets.babel7StringConfig, PackageSets.typescript2_7]
10-
export const allPackageSetsWithPreset = [PackageSets.default, PackageSets.babel7, PackageSets.babel7StringConfig, PackageSets.typescript2_7]
9+
export const allValidPackageSets = [PackageSets.default, PackageSets.babel7, PackageSets.babel7StringConfig, PackageSets.typescript2_7],
10+
allPackageSetsWithPreset = [PackageSets.default, PackageSets.babel7, PackageSets.babel7StringConfig, PackageSets.typescript2_7],
11+
allPackageSetsWithProgram = [PackageSets.default, PackageSets.babel7, PackageSets.babel7StringConfig],
12+
allPackageSetsWithoutProgram = [PackageSets.typescript2_7, PackageSets.unsupportedVersion]

e2e/__monorepos__/simple/with-dependency/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"ts-jest": {
3333
"diagnostics": true,
3434
"tsConfig": "<rootDir>/tsconfig.json",
35-
"compilerHost": true
35+
"compilerHost": true,
36+
"incremental": true
3637
}
3738
}
3839
},

0 commit comments

Comments
 (0)