Skip to content

Commit c07096a

Browse files
committed
docs(config): adds doc for some config options
Adds doc for options: `compiler`, `tsConfig`, `isolatedModules`
1 parent d8fe6a8 commit c07096a

4 files changed

Lines changed: 217 additions & 28 deletions

File tree

docs/user/config.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ In most of the case, simply adding `preset: 'ts-jest'` to your Jest config shoul
1111

1212
<div class="row"><div class="col-md-6" markdown="block">
1313
```js
14-
// package.json
14+
// jest.config.js
15+
module.exports = {
16+
// [...]
17+
preset: 'ts-jest'
18+
};
19+
```
20+
</div><div class="col-md-6" markdown="block">
21+
```js
22+
// OR package.json
1523
{
1624
// [...]
1725
"jest": {
1826
"preset": "ts-jest"
1927
}
2028
}
2129
```
22-
</div><div class="col-md-6" markdown="block">
23-
```js
24-
// jest.config.js
25-
module.exports = {
26-
// [...]
27-
preset: 'ts-jest'
28-
};
29-
```
3030
</div></div>
3131

3232
### Advanced
@@ -53,7 +53,19 @@ All configration of TSJest specific options are located under `globals.ts-jest`
5353

5454
<div class="row"><div class="col-md-6" markdown="block">
5555
```js
56-
// package.json
56+
// jest.config.js
57+
module.exports = {
58+
// [...]
59+
globals: {
60+
'ts-jest': {
61+
// TSJest configuration goes here
62+
}
63+
}
64+
};
65+
```
66+
</div><div class="col-md-6" markdown="block">
67+
```js
68+
// OR package.json
5769
{
5870
// [...]
5971
"jest": {
@@ -65,27 +77,15 @@ All configration of TSJest specific options are located under `globals.ts-jest`
6577
}
6678
}
6779
```
68-
</div><div class="col-md-6" markdown="block">
69-
```js
70-
// jest.config.js
71-
module.exports = {
72-
// [...]
73-
globals: {
74-
'ts-jest': {
75-
// TSJest configuration goes here
76-
}
77-
}
78-
};
79-
```
8080
</div></div>
8181

8282
### Options
8383

8484
All options have default values which should fit most of the projects.
8585

86-
- **`compiler`**: TypeScript module to use as compiler.
87-
- **`tsConfig`**: TypeScript compiler related configuration.
88-
- **`isolatedModules`**: Enables/disables the TypeScript language service.
89-
- **`diagnostics`**: Diagnostics related configuration.
90-
- **`babelConfig`**: Babel(Jest) related configuration.
91-
- **`stringifyContentPathRegex`**: Configure which file(s) will become a module returning its content.
86+
- [**`compiler`**: TypeScript module to use as compiler](config/compiler).
87+
- [**`tsConfig`**: TypeScript compiler related configuration.](config/tsConfig)
88+
- [**`isolatedModules`**: Enables/disables the TypeScript language service.](config/isolatedModules)
89+
- [**`diagnostics`**: Diagnostics related configuration.](config/diagnostics)
90+
- [**`babelConfig`**: Babel(Jest) related configuration.](config/babelConfig)
91+
- [**`stringifyContentPathRegex`**: Configure which file(s) will become a module returning its content.](config/stringifyContentPathRegex)

docs/user/config/compiler.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: Compiler option
3+
---
4+
5+
The `compiler` option allows you to define the compiler to be used. It'll be used to load the NodeJS module holding the TypeScript compiler.
6+
7+
The default value is `typescript`, which will load the original [TypeScript compiler module](https://www.npmjs.com/package/typescript). The version loaded will depend on the one installed in your project.
8+
9+
If you use a custom compiler, such as `ttypescript` for example, be sure its API is the same as the original TypeScript, at least for what TSJest is using.
10+
11+
### Example:
12+
13+
<div class="row"><div class="col-md-6" markdown="block">
14+
```js
15+
// jest.config.js
16+
module.exports = {
17+
// [...]
18+
globals: {
19+
'ts-jest': {
20+
compiler: 'ttypsecript'
21+
}
22+
}
23+
};
24+
```
25+
</div><div class="col-md-6" markdown="block">
26+
```js
27+
// OR package.json
28+
{
29+
// [...]
30+
"jest": {
31+
"globals": {
32+
"ts-jest": {
33+
"compiler": "ttypsecript"
34+
}
35+
}
36+
}
37+
}
38+
```
39+
</div></div>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: Isolated Modules option
3+
---
4+
5+
By default TSJest uses TypeScript compiler in the context of a project (yours), with full type-checking and features. But it can also be used to compile each file separatly, as an isolated module. That's what the `isolatedModules` option (which defaults to `false`) comes for.
6+
7+
You'll loose type-checking ability and some features such as `const enum`, but in the case you plan on using Jest with the cache disabled (`jest --no-cache`), your tests will then run much faster.
8+
9+
Here is how to disable type-checking and compile each file as an isolated module:
10+
11+
### Example:
12+
13+
<div class="row"><div class="col-md-6" markdown="block">
14+
```js
15+
// jest.config.js
16+
module.exports = {
17+
// [...]
18+
globals: {
19+
'ts-jest': {
20+
isolatedModules: true
21+
}
22+
}
23+
};
24+
```
25+
</div><div class="col-md-6" markdown="block">
26+
```js
27+
// OR package.json
28+
{
29+
// [...]
30+
"jest": {
31+
"globals": {
32+
"ts-jest": {
33+
"isolatedModules": false
34+
}
35+
}
36+
}
37+
}
38+
```
39+
</div></div>

docs/user/config/tsConfig.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
title: TypeScript Config option
3+
---
4+
5+
The `tsConfig` option allows you to define the which `tsconfig` JSON file to use. An inline compiler options object can also be specified instead of the path to a file.
6+
7+
By default, TSJest will do like `tsc` and use the project's `tsconfig.json` file. If it cannot find one, it'l use defaults TypeScript compiler options (except `es5` is used as target instead of `es3`).
8+
9+
If you need to use defaults and force TSJest to use the defaults even if there is a `tsconfig.json`, you can set this option to `false`.
10+
11+
#### Examples
12+
13+
### Path to a `tsconfig` file:
14+
15+
The path should be relative to the current working directory where you start Jest from. You can also use `<rootDir>` in the path, or use an absolute path (this last one is strongly not recommanded).
16+
17+
<div class="row"><div class="col-md-6" markdown="block">
18+
```js
19+
// jest.config.js
20+
module.exports = {
21+
// [...]
22+
globals: {
23+
'ts-jest': {
24+
tsConfig: 'tsconfig.test.json'
25+
}
26+
}
27+
};
28+
```
29+
</div><div class="col-md-6" markdown="block">
30+
```js
31+
// OR package.json
32+
{
33+
// [...]
34+
"jest": {
35+
"globals": {
36+
"ts-jest": {
37+
"tsConfig": "tsconfig.test.json"
38+
}
39+
}
40+
}
41+
}
42+
```
43+
</div></div>
44+
45+
### Inline compiler options:
46+
47+
Refer to the [TypeScript compiler options](https://www.typescriptlang.org/docs/handbook/compiler-options.html) to know what can be used. It's basically the same that you'd put in your `tsconfig.json`'s `compilerOptions`.
48+
49+
<div class="row"><div class="col-md-6" markdown="block">
50+
```js
51+
// jest.config.js
52+
module.exports = {
53+
// [...]
54+
globals: {
55+
'ts-jest': {
56+
tsConfig: {
57+
importHelpers: true
58+
}
59+
}
60+
}
61+
};
62+
```
63+
</div><div class="col-md-6" markdown="block">
64+
```js
65+
// OR package.json
66+
{
67+
// [...]
68+
"jest": {
69+
"globals": {
70+
"ts-jest": {
71+
"tsConfig": {
72+
"importHelpers": true
73+
}
74+
}
75+
}
76+
}
77+
}
78+
```
79+
</div></div>
80+
81+
### Disable auto-lookup:
82+
83+
By default TSJest will try to find the `tsconfig.json` in your project. But you may want to not use it at all and keep TypeScript default options. You can achieve this by setting `tsConfig` to `false`.
84+
85+
<div class="row"><div class="col-md-6" markdown="block">
86+
```js
87+
// jest.config.js
88+
module.exports = {
89+
// [...]
90+
globals: {
91+
'ts-jest': {
92+
tsConfig: false
93+
}
94+
}
95+
};
96+
```
97+
</div><div class="col-md-6" markdown="block">
98+
```js
99+
// OR package.json
100+
{
101+
// [...]
102+
"jest": {
103+
"globals": {
104+
"ts-jest": {
105+
"tsConfig": false
106+
}
107+
}
108+
}
109+
}
110+
```
111+
</div></div>

0 commit comments

Comments
 (0)