| 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. compilerHostis enabled:incrementalis enabled (default): use TypeScriptIncremental Program.incrementalis disabled: use TypeScriptProgram.
isolatedModulesis enabled, use TypeScript transpile modules.
Here is how to enable ts-jest to compile using TypeScript Program
// jest.config.js
module.exports = {
// [...]
globals: {
'ts-jest': {
compilerHost: true,
incremental: false,
}
}
};// OR package.json
{
// [...]
"jest": {
"globals": {
"ts-jest": {
"compilerHost": true,
"incremental": false
}
}
}
}Here is how to enable ts-jest to compile using TypeScript IncrementalProgram
// jest.config.js
module.exports = {
// [...]
globals: {
'ts-jest': {
compilerHost: true
}
}
};// OR package.json
{
// [...]
"jest": {
"globals": {
"ts-jest": {
"compilerHost": true
}
}
}
}