Skip to content

Commit 4ebacd7

Browse files
authored
docs(devs-infra): update docs to reflect transformer config (#3782)
1 parent 31e5843 commit 4ebacd7

11 files changed

Lines changed: 325 additions & 203 deletions

File tree

website/docs/getting-started/options.md

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@ title: Options
55

66
### Introduction
77

8-
All `ts-jest` specific options are located under the `globals` of Jest config object in the `package.json` file of your project,
8+
All `ts-jest` specific options can be defined in Jest `transform` config object in the `package.json` file of your project,
99
or through a `jest.config.js`, or `jest.config.ts` file.
1010

1111
```json
1212
// package.json
1313
{
1414
// [...]
1515
"jest": {
16-
"globals": {
17-
"ts-jest": {
18-
// ts-jest configuration goes here
19-
}
16+
"transform": {
17+
"<regex_match_files>": [
18+
"ts-jest",
19+
{
20+
// ts-jest configuration goes here
21+
}
22+
]
2023
}
2124
}
2225
}
@@ -28,10 +31,13 @@ Or through JavaScript:
2831
// jest.config.js
2932
module.exports = {
3033
// [...]
31-
globals: {
32-
'ts-jest': {
33-
// ts-jest configuration goes here
34-
},
34+
transform: {
35+
'<regex_match_files>': [
36+
'ts-jest',
37+
{
38+
// ts-jest configuration goes here
39+
},
40+
],
3541
},
3642
}
3743
```
@@ -44,10 +50,13 @@ To utilize IDE suggestions, you can use `JSDoc` comments to provide suggested `t
4450
/** @type {import('ts-jest').InitialOptionsTsJest} */
4551
module.exports = config = {
4652
// [...]
47-
globals: {
48-
'ts-jest': {
49-
// ts-jest configuration goes here and your IDE will suggest which configs when typing
50-
},
53+
transform: {
54+
'<regex_match_files>': [
55+
'ts-jest',
56+
{
57+
// ts-jest configuration goes here and your IDE will suggest which configs when typing
58+
},
59+
],
5160
},
5261
}
5362
```
@@ -61,10 +70,13 @@ Or through TypeScript (if `ts-node` is installed):
6170
import type { InitialOptionsTsJest } from 'ts-jest'
6271

6372
const config: InitialOptionsTsJest = {
64-
globals: {
65-
'ts-jest': {
66-
// ts-jest configuration goes here
67-
},
73+
transform: {
74+
'<regex_match_files>': [
75+
'ts-jest',
76+
{
77+
// ts-jest configuration goes here
78+
},
79+
],
6880
},
6981
}
7082
export default config

website/docs/getting-started/options/astTransformers.md

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ The option is `astTransformers` and it allows ones to specify which 3 types of T
2020
// jest.config.js
2121
module.exports = {
2222
// [...]
23-
globals: {
24-
'ts-jest': {
25-
astTransformers: {
26-
before: ['my-custom-transformer'],
23+
transform: {
24+
'<regex_match_files>': [
25+
'ts-jest',
26+
{
27+
astTransformers: {
28+
before: ['my-custom-transformer'],
29+
},
2730
},
28-
},
31+
],
2932
},
3033
}
3134
```
@@ -35,12 +38,15 @@ module.exports = {
3538
{
3639
// [...]
3740
"jest": {
38-
"globals": {
39-
"ts-jest": {
40-
"astTransformers": {
41-
"before": ["my-custom-transformer"]
41+
"transform": {
42+
"<regex_match_files>": [
43+
"ts-jest",
44+
{
45+
"astTransformers": {
46+
"before": ["my-custom-transformer"]
47+
}
4248
}
43-
}
49+
]
4450
}
4551
}
4652
}
@@ -52,17 +58,20 @@ module.exports = {
5258
// jest.config.js
5359
module.exports = {
5460
// [...]
55-
globals: {
56-
'ts-jest': {
57-
astTransformers: {
58-
before: [
59-
{
60-
path: 'my-custom-transformer-that-needs-extra-opts',
61-
options: {}, // extra options to pass to transformers here
62-
},
63-
],
61+
transform: {
62+
'<regex_match_files>': [
63+
'ts-jest',
64+
{
65+
astTransformers: {
66+
before: [
67+
{
68+
path: 'my-custom-transformer-that-needs-extra-opts',
69+
options: {}, // extra options to pass to transformers here
70+
},
71+
],
72+
},
6473
},
65-
},
74+
],
6675
},
6776
}
6877
```
@@ -72,17 +81,20 @@ module.exports = {
7281
{
7382
// [...]
7483
"jest": {
75-
"globals": {
76-
"ts-jest": {
77-
"astTransformers": {
78-
"before": [
79-
{
80-
"path": "my-custom-transformer-that-needs-extra-opts",
81-
"options": {} // extra options to pass to transformers here
82-
}
83-
]
84+
"transform": {
85+
"<regex_match_files>": [
86+
"ts-jest",
87+
{
88+
"astTransformers": {
89+
"before": [
90+
{
91+
"path": "my-custom-transformer-that-needs-extra-opts",
92+
"options": {} // extra options to pass to transformers here
93+
}
94+
]
95+
}
8496
}
85-
}
97+
]
8698
}
8799
}
88100
}

website/docs/getting-started/options/babelConfig.md

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ The option is `babelConfig` and it works pretty much as the `tsconfig` option, e
1818
// jest.config.js
1919
module.exports = {
2020
// [...]
21-
globals: {
22-
'ts-jest': {
23-
babelConfig: true,
24-
},
21+
transform: {
22+
'<regex_match_files>': [
23+
'ts-jest',
24+
{
25+
babelConfig: true,
26+
},
27+
],
2528
},
2629
}
2730
```
@@ -31,10 +34,13 @@ module.exports = {
3134
{
3235
// [...]
3336
"jest": {
34-
"globals": {
35-
"ts-jest": {
36-
"babelConfig": true
37-
}
37+
"transform": {
38+
"<regex_match_files>": [
39+
"ts-jest",
40+
{
41+
"babelConfig": true
42+
}
43+
]
3844
}
3945
}
4046
}
@@ -48,10 +54,13 @@ The path should be relative to the current working directory where you start Jes
4854
// jest.config.js
4955
module.exports = {
5056
// [...]
51-
globals: {
52-
'ts-jest': {
53-
babelConfig: 'babelrc.test.js',
54-
},
57+
transform: {
58+
'<regex_match_files>': [
59+
'ts-jest',
60+
{
61+
babelConfig: 'babelrc.test.js',
62+
},
63+
],
5564
},
5665
}
5766
```
@@ -60,10 +69,13 @@ module.exports = {
6069
// OR jest.config.js with require for babelrc
6170
module.exports = {
6271
// [...]
63-
globals: {
64-
'ts-jest': {
65-
babelConfig: require('./babelrc.test.js'),
66-
},
72+
transform: {
73+
'<regex_match_files>': [
74+
'ts-jest',
75+
{
76+
babelConfig: require('./babelrc.test.js'),
77+
},
78+
],
6779
},
6880
}
6981
```
@@ -73,10 +85,13 @@ module.exports = {
7385
{
7486
// [...]
7587
"jest": {
76-
"globals": {
77-
"ts-jest": {
78-
"babelConfig": "babelrc.test.js"
79-
}
88+
"transform": {
89+
"<regex_match_files>": [
90+
"ts-jest",
91+
{
92+
"babelConfig": "babelrc.test.js"
93+
}
94+
]
8095
}
8196
}
8297
}
@@ -90,13 +105,16 @@ Refer to the [Babel options](https://babeljs.io/docs/en/next/options) to know wh
90105
// jest.config.js
91106
module.exports = {
92107
// [...]
93-
globals: {
94-
'ts-jest': {
95-
babelConfig: {
96-
comments: false,
97-
plugins: ['@babel/plugin-transform-for-of'],
108+
transform: {
109+
'<regex_match_files>': [
110+
'ts-jest',
111+
{
112+
babelConfig: {
113+
comments: false,
114+
plugins: ['@babel/plugin-transform-for-of'],
115+
},
98116
},
99-
},
117+
],
100118
},
101119
}
102120
```
@@ -106,13 +124,16 @@ module.exports = {
106124
{
107125
// [...]
108126
"jest": {
109-
"globals": {
110-
"ts-jest": {
111-
"babelConfig": {
112-
"comments": false,
113-
"plugins": ["@babel/plugin-transform-for-of"]
127+
"transform": {
128+
"<regex_match_files>": [
129+
"ts-jest",
130+
{
131+
"babelConfig": {
132+
"comments": false,
133+
"plugins": ["@babel/plugin-transform-for-of"]
134+
}
114135
}
115-
}
136+
]
116137
}
117138
}
118139
}

website/docs/getting-started/options/compiler.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ If you use a custom compiler, such as `ttypescript`, make sure its API is the sa
1515
// jest.config.js
1616
module.exports = {
1717
// [...]
18-
globals: {
19-
'ts-jest': {
20-
compiler: 'ttypescript',
21-
},
18+
transform: {
19+
'<regex_match_files': [
20+
'ts-jest',
21+
{
22+
compiler: 'ttypescript',
23+
},
24+
],
2225
},
2326
}
2427
```
@@ -28,10 +31,13 @@ module.exports = {
2831
{
2932
// [...]
3033
"jest": {
31-
"globals": {
32-
"ts-jest": {
33-
"compiler": "ttypescript"
34-
}
34+
"transform": {
35+
"<regex_match_files>": [
36+
"ts-jest",
37+
{
38+
"compiler": "ttypescript"
39+
}
40+
]
3541
}
3642
}
3743
}

0 commit comments

Comments
 (0)