Skip to content

Commit

Permalink
chore(compiler): use Incremental Program for compilerHost option (#…
Browse files Browse the repository at this point in the history
…1535)

BREAKING CHANGE: `incremental` option is no longer available. By default, `compilerHost` always uses TypeScript `Incremental Program`
  • Loading branch information
ahnpnl committed Apr 17, 2020
1 parent d6472a3 commit a7250b6
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 808 deletions.
55 changes: 5 additions & 50 deletions docs/user/config/compilerHost.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@ title: Compiler Host option
---

By default `ts-jest` uses TypeScript `LanguageService` API in the context of a project (yours), with full type-checking and features.
But TypeScript `Program` can also be used to achieve the same behavior as `LanguageService`.
But TypeScript `Incremental Program` can also be used to achieve the same behavior as `LanguageService`.
That's what the `compilerHost` option (which defaults to `false`) does.

There are 2 types of TypeScript `Program`, one is `Incremental Program` which is only available from TypeScript 3.4
and the other one is normal `Program`.

By default `ts-jest` uses `Incremental Program` if `compilerHost` is enabled. The priority of using TypeScript APIs in `ts-jest`
as below:
The priority of using TypeScript APIs in `ts-jest` as below:
- Default TypeScript API is `LanguageService`.
- `compilerHost` is enabled:
- `incremental` is enabled (**default**): use TypeScript `Incremental Program`.
- `incremental` is disabled: use TypeScript `Program`.
- `isolatedModules` is enabled, use TypeScript transpile modules.
- `compilerHost` is enabled: use TypeScript `Incremental Program`.
- `isolatedModules` is enabled: use TypeScript transpile modules.

Here is how to enable `ts-jest` to compile using TypeScript `Program`
Here is how to enable `ts-jest` to compile using TypeScript `Incremental Program`

### Example

Expand All @@ -30,7 +24,6 @@ module.exports = {
globals: {
'ts-jest': {
compilerHost: true,
incremental: false,
}
}
};
Expand All @@ -46,44 +39,6 @@ module.exports = {
"globals": {
"ts-jest": {
"compilerHost": true,
"incremental": false
}
}
}
}
```

</div></div>


Here is how to enable `ts-jest` to compile using TypeScript `IncrementalProgram`

### Example

<div class="row"><div class="col-md-6" markdown="block">

```js
// jest.config.js
module.exports = {
// [...]
globals: {
'ts-jest': {
compilerHost: true
}
}
};
```

</div><div class="col-md-6" markdown="block">

```js
// OR package.json
{
// [...]
"jest": {
"globals": {
"ts-jest": {
"compilerHost": true
}
}
}
Expand Down
1 change: 0 additions & 1 deletion docs/user/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ All options have default values which should fit most of the projects. Click on
| [**`tsConfig`**][tsConfig] | [TypeScript compiler related configuration.][tsConfig] | `string`\|`object`\|`boolean` | _auto_ |
| [**`isolatedModules`**][isolatedModules] | [Disable type-checking][isolatedModules] | `boolean` | `false` |
| [**`compilerHost`**][compilerHost] | [Use TypeScript Compiler API][compilerHost] | `boolean` | `false` |
| [**`incremental (use with `compilerHost`)`**][compilerHost] | [Use TypeScript Incremental Program][compilerHost] | `boolean` | `true` |
| [**`diagnostics`**][diagnostics] | [Diagnostics related configuration.][diagnostics] | `boolean`\|`object` | `true` |
| [**`babelConfig`**][babelConfig] | [Babel(Jest) related configuration.][babelConfig] | `boolean`\|`object` | _disabled_ |
| [**`stringifyContentPathRegex`**][stringifyContentPathRegex] | [Files which will become modules returning self content.][stringifyContentPathRegex] | `string`\|`RegExp` | _disabled_ |
Expand Down
3 changes: 1 addition & 2 deletions e2e/__external-repos__/simple/with-dependency/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
"globals": {
"ts-jest": {
"diagnostics": true,
"tsConfig": "<rootDir>/tsconfig.json",
"compilerHost": true
"tsConfig": "<rootDir>/tsconfig.json"
}
}
},
Expand Down
231 changes: 0 additions & 231 deletions e2e/__tests__/__snapshots__/diagnostics.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -462,237 +462,6 @@ exports[`With diagnostics throw using language service then pass when type has c
================================================================================
`;
exports[`With diagnostics throw using program first throw should fail using template "default" 1`] = `
× jest
↳ exit code: 1
===[ STDOUT ]===================================================================
===[ STDERR ]===================================================================
FAIL ./main.spec.ts
● Test suite failed to run
main.spec.ts:3:14 - error TS2741: Property 'b' is missing in type '{ a: number; }' but required in type 'Thing'.
3 export const thing: Thing = { a: 1 };
~~~~~
main.ts:2:34
2 export type Thing = { a: number, b: number }
~
'b' is declared here.
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;
exports[`With diagnostics throw using program first throw should fail using template "with-babel-7" 1`] = `
× jest
↳ exit code: 1
===[ STDOUT ]===================================================================
===[ STDERR ]===================================================================
FAIL ./main.spec.ts
● Test suite failed to run
main.spec.ts:3:14 - error TS2741: Property 'b' is missing in type '{ a: number; }' but required in type 'Thing'.
3 export const thing: Thing = { a: 1 };
~~~~~
main.ts:2:34
2 export type Thing = { a: number, b: number }
~
'b' is declared here.
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;
exports[`With diagnostics throw using program first throw should fail using template "with-babel-7-string-config" 1`] = `
× jest
↳ exit code: 1
===[ STDOUT ]===================================================================
===[ STDERR ]===================================================================
FAIL ./main.spec.ts
● Test suite failed to run
main.spec.ts:3:14 - error TS2741: Property 'b' is missing in type '{ a: number; }' but required in type 'Thing'.
3 export const thing: Thing = { a: 1 };
~~~~~
main.ts:2:34
2 export type Thing = { a: number, b: number }
~
'b' is declared here.
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;
exports[`With diagnostics throw using program then failed when type has changed to invalid base on cache of the previous run should fail using template "default" 1`] = `
× jest
↳ exit code: 1
===[ STDOUT ]===================================================================
===[ STDERR ]===================================================================
FAIL ./main.spec.ts
× foo is 42
● foo is 42
expect(received).toBe(expected) // Object.is equality
Expected: 42
Received: 43
4 |
5 | test('foo is 42', () => {
> 6 | expect(foo).toBe(42);
| ^
7 | });
8 |
at Object.<anonymous> (main.spec.ts:6:15)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;
exports[`With diagnostics throw using program then failed when type has changed to invalid base on cache of the previous run should fail using template "with-babel-7" 1`] = `
× jest
↳ exit code: 1
===[ STDOUT ]===================================================================
===[ STDERR ]===================================================================
FAIL ./main.spec.ts
× foo is 42
● foo is 42
expect(received).toBe(expected) // Object.is equality
Expected: 42
Received: 43
4 |
5 | test('foo is 42', () => {
> 6 | expect(foo).toBe(42);
| ^
7 | });
8 |
at Object.<anonymous> (main.spec.ts:6:15)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;
exports[`With diagnostics throw using program then failed when type has changed to invalid base on cache of the previous run should fail using template "with-babel-7-string-config" 1`] = `
× jest
↳ exit code: 1
===[ STDOUT ]===================================================================
===[ STDERR ]===================================================================
FAIL ./main.spec.ts
× foo is 42
● foo is 42
expect(received).toBe(expected) // Object.is equality
Expected: 42
Received: 43
4 |
5 | test('foo is 42', () => {
> 6 | expect(foo).toBe(42);
| ^
7 | });
8 |
at Object.<anonymous> (main.spec.ts:6:15)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;
exports[`With diagnostics throw using program then pass when type has changed to valid base on cache of the previous run should pass using template "default" 1`] = `
√ jest
↳ exit code: 0
===[ STDOUT ]===================================================================
===[ STDERR ]===================================================================
PASS ./main.spec.ts
√ foo is 42
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;
exports[`With diagnostics throw using program then pass when type has changed to valid base on cache of the previous run should pass using template "with-babel-7" 1`] = `
√ jest
↳ exit code: 0
===[ STDOUT ]===================================================================
===[ STDERR ]===================================================================
PASS ./main.spec.ts
√ foo is 42
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;
exports[`With diagnostics throw using program then pass when type has changed to valid base on cache of the previous run should pass using template "with-babel-7-string-config" 1`] = `
√ jest
↳ exit code: 0
===[ STDOUT ]===================================================================
===[ STDERR ]===================================================================
PASS ./main.spec.ts
√ foo is 42
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;
exports[`With diagnostics warn only should pass using template "default" 1`] = `
√ jest --no-cache
↳ exit code: 0
Expand Down

0 comments on commit a7250b6

Please sign in to comment.