-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): add incremental option (#1418)
- Loading branch information
Showing
32 changed files
with
732 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--- | ||
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`. | ||
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: | ||
- 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. | ||
|
||
Here is how to enable `ts-jest` to compile using TypeScript `Program` | ||
|
||
### Example | ||
|
||
<div class="row"><div class="col-md-6" markdown="block"> | ||
|
||
```js | ||
// jest.config.js | ||
module.exports = { | ||
// [...] | ||
globals: { | ||
'ts-jest': { | ||
compilerHost: true, | ||
incremental: false, | ||
} | ||
} | ||
}; | ||
``` | ||
|
||
</div><div class="col-md-6" markdown="block"> | ||
|
||
```js | ||
// OR package.json | ||
{ | ||
// [...] | ||
"jest": { | ||
"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 | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
</div></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { g } from './main' | ||
|
||
it('should pass', () => { | ||
const x: string = g(5) | ||
expect(x).toBe(5) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const g = (v: number) => v |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`With compilerHost enabled and incremental disabled should fail using template "with-typescript-2-7" 1`] = ` | ||
× jest --no-cache | ||
↳ exit code: 1 | ||
===[ STDOUT ]=================================================================== | ||
===[ STDERR ]=================================================================== | ||
FAIL ./main.spec.ts | ||
● Test suite failed to run | ||
TypeError: Cannot read property 'maxNodeModuleJsDepth' of undefined | ||
at Object.createProgram (../../__templates__/with-typescript-2-7/node_modules/typescript/lib/typescript.js:73929:51) | ||
Test Suites: 1 failed, 1 total | ||
Tests: 0 total | ||
Snapshots: 0 total | ||
Time: XXs | ||
Ran all test suites. | ||
================================================================================ | ||
`; | ||
|
||
exports[`With compilerHost enabled and incremental disabled should fail using template "with-unsupported-version" 1`] = ` | ||
× jest --no-cache | ||
↳ exit code: 1 | ||
===[ STDOUT ]=================================================================== | ||
===[ STDERR ]=================================================================== | ||
ts-jest[versions] (WARN) Version 2.5.3 of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=2.7.0 <4.0.0). Please do not report issues in ts-jest if you are using unsupported versions. | ||
FAIL ./main.spec.ts | ||
● Test suite failed to run | ||
TypeError: Cannot read property 'maxNodeModuleJsDepth' of undefined | ||
at Object.createProgram (../../__templates__/with-unsupported-version/node_modules/typescript/lib/typescript.js:69709:51) | ||
Test Suites: 1 failed, 1 total | ||
Tests: 0 total | ||
Snapshots: 0 total | ||
Time: XXs | ||
Ran all test suites. | ||
================================================================================ | ||
`; | ||
|
||
exports[`With compilerHost enabled and incremental disabled should pass using template "default" 1`] = ` | ||
√ jest --no-cache | ||
↳ exit code: 0 | ||
===[ STDOUT ]=================================================================== | ||
===[ STDERR ]=================================================================== | ||
ts-jest[ts-compiler] (WARN) TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option): | ||
main.spec.ts:4:9 - error TS2322: Type 'number' is not assignable to type 'string'. | ||
4 const x: string = g(5) | ||
~ | ||
PASS ./main.spec.ts | ||
√ should pass | ||
Test Suites: 1 passed, 1 total | ||
Tests: 1 passed, 1 total | ||
Snapshots: 0 total | ||
Time: XXs | ||
Ran all test suites. | ||
================================================================================ | ||
`; | ||
|
||
exports[`With compilerHost enabled and incremental disabled should pass using template "with-babel-7" 1`] = ` | ||
√ jest --no-cache | ||
↳ exit code: 0 | ||
===[ STDOUT ]=================================================================== | ||
===[ STDERR ]=================================================================== | ||
ts-jest[ts-compiler] (WARN) TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option): | ||
main.spec.ts:4:9 - error TS2322: Type 'number' is not assignable to type 'string'. | ||
4 const x: string = g(5) | ||
~ | ||
PASS ./main.spec.ts | ||
√ should pass | ||
Test Suites: 1 passed, 1 total | ||
Tests: 1 passed, 1 total | ||
Snapshots: 0 total | ||
Time: XXs | ||
Ran all test suites. | ||
================================================================================ | ||
`; | ||
|
||
exports[`With compilerHost enabled and incremental disabled should pass using template "with-babel-7-string-config" 1`] = ` | ||
√ jest --no-cache | ||
↳ exit code: 0 | ||
===[ STDOUT ]=================================================================== | ||
===[ STDERR ]=================================================================== | ||
ts-jest[ts-compiler] (WARN) TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option): | ||
main.spec.ts:4:9 - error TS2322: Type 'number' is not assignable to type 'string'. | ||
4 const x: string = g(5) | ||
~ | ||
PASS ./main.spec.ts | ||
√ should pass | ||
Test Suites: 1 passed, 1 total | ||
Tests: 1 passed, 1 total | ||
Snapshots: 0 total | ||
Time: XXs | ||
Ran all test suites. | ||
================================================================================ | ||
`; | ||
|
||
exports[`With compilerHost enabled and incremental enabled should fail using template "with-typescript-2-7" 1`] = ` | ||
× jest --no-cache | ||
↳ exit code: 1 | ||
===[ STDOUT ]=================================================================== | ||
===[ STDERR ]=================================================================== | ||
FAIL ./main.spec.ts | ||
● Test suite failed to run | ||
TypeError: Cannot read property 'maxNodeModuleJsDepth' of undefined | ||
at Object.createProgram (../../__templates__/with-typescript-2-7/node_modules/typescript/lib/typescript.js:73929:51) | ||
Test Suites: 1 failed, 1 total | ||
Tests: 0 total | ||
Snapshots: 0 total | ||
Time: XXs | ||
Ran all test suites. | ||
================================================================================ | ||
`; | ||
|
||
exports[`With compilerHost enabled and incremental enabled should fail using template "with-unsupported-version" 1`] = ` | ||
× jest --no-cache | ||
↳ exit code: 1 | ||
===[ STDOUT ]=================================================================== | ||
===[ STDERR ]=================================================================== | ||
ts-jest[versions] (WARN) Version 2.5.3 of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=2.7.0 <4.0.0). Please do not report issues in ts-jest if you are using unsupported versions. | ||
FAIL ./main.spec.ts | ||
● Test suite failed to run | ||
TypeError: Cannot read property 'maxNodeModuleJsDepth' of undefined | ||
at Object.createProgram (../../__templates__/with-unsupported-version/node_modules/typescript/lib/typescript.js:69709:51) | ||
Test Suites: 1 failed, 1 total | ||
Tests: 0 total | ||
Snapshots: 0 total | ||
Time: XXs | ||
Ran all test suites. | ||
================================================================================ | ||
`; | ||
|
||
exports[`With compilerHost enabled and incremental enabled should pass using template "default" 1`] = ` | ||
√ jest --no-cache | ||
↳ exit code: 0 | ||
===[ STDOUT ]=================================================================== | ||
===[ STDERR ]=================================================================== | ||
ts-jest[ts-compiler] (WARN) TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option): | ||
main.spec.ts:4:9 - error TS2322: Type 'number' is not assignable to type 'string'. | ||
4 const x: string = g(5) | ||
~ | ||
PASS ./main.spec.ts | ||
√ should pass | ||
Test Suites: 1 passed, 1 total | ||
Tests: 1 passed, 1 total | ||
Snapshots: 0 total | ||
Time: XXs | ||
Ran all test suites. | ||
================================================================================ | ||
`; | ||
|
||
exports[`With compilerHost enabled and incremental enabled should pass using template "with-babel-7" 1`] = ` | ||
√ jest --no-cache | ||
↳ exit code: 0 | ||
===[ STDOUT ]=================================================================== | ||
===[ STDERR ]=================================================================== | ||
ts-jest[ts-compiler] (WARN) TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option): | ||
main.spec.ts:4:9 - error TS2322: Type 'number' is not assignable to type 'string'. | ||
4 const x: string = g(5) | ||
~ | ||
PASS ./main.spec.ts | ||
√ should pass | ||
Test Suites: 1 passed, 1 total | ||
Tests: 1 passed, 1 total | ||
Snapshots: 0 total | ||
Time: XXs | ||
Ran all test suites. | ||
================================================================================ | ||
`; | ||
|
||
exports[`With compilerHost enabled and incremental enabled should pass using template "with-babel-7-string-config" 1`] = ` | ||
√ jest --no-cache | ||
↳ exit code: 0 | ||
===[ STDOUT ]=================================================================== | ||
===[ STDERR ]=================================================================== | ||
ts-jest[ts-compiler] (WARN) TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option): | ||
main.spec.ts:4:9 - error TS2322: Type 'number' is not assignable to type 'string'. | ||
4 const x: string = g(5) | ||
~ | ||
PASS ./main.spec.ts | ||
√ should pass | ||
Test Suites: 1 passed, 1 total | ||
Tests: 1 passed, 1 total | ||
Snapshots: 0 total | ||
Time: XXs | ||
Ran all test suites. | ||
================================================================================ | ||
`; |
Oops, something went wrong.