Skip to content

Commit

Permalink
docs(devs-infra): update docs to reflect transformer config (#3782)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnpnl committed Aug 28, 2022
1 parent 31e5843 commit 4ebacd7
Show file tree
Hide file tree
Showing 11 changed files with 325 additions and 203 deletions.
46 changes: 29 additions & 17 deletions website/docs/getting-started/options.md
Expand Up @@ -5,18 +5,21 @@ title: Options

### Introduction

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

```json
// package.json
{
// [...]
"jest": {
"globals": {
"ts-jest": {
// ts-jest configuration goes here
}
"transform": {
"<regex_match_files>": [
"ts-jest",
{
// ts-jest configuration goes here
}
]
}
}
}
Expand All @@ -28,10 +31,13 @@ Or through JavaScript:
// jest.config.js
module.exports = {
// [...]
globals: {
'ts-jest': {
// ts-jest configuration goes here
},
transform: {
'<regex_match_files>': [
'ts-jest',
{
// ts-jest configuration goes here
},
],
},
}
```
Expand All @@ -44,10 +50,13 @@ To utilize IDE suggestions, you can use `JSDoc` comments to provide suggested `t
/** @type {import('ts-jest').InitialOptionsTsJest} */
module.exports = config = {
// [...]
globals: {
'ts-jest': {
// ts-jest configuration goes here and your IDE will suggest which configs when typing
},
transform: {
'<regex_match_files>': [
'ts-jest',
{
// ts-jest configuration goes here and your IDE will suggest which configs when typing
},
],
},
}
```
Expand All @@ -61,10 +70,13 @@ Or through TypeScript (if `ts-node` is installed):
import type { InitialOptionsTsJest } from 'ts-jest'

const config: InitialOptionsTsJest = {
globals: {
'ts-jest': {
// ts-jest configuration goes here
},
transform: {
'<regex_match_files>': [
'ts-jest',
{
// ts-jest configuration goes here
},
],
},
}
export default config
Expand Down
72 changes: 42 additions & 30 deletions website/docs/getting-started/options/astTransformers.md
Expand Up @@ -20,12 +20,15 @@ The option is `astTransformers` and it allows ones to specify which 3 types of T
// jest.config.js
module.exports = {
// [...]
globals: {
'ts-jest': {
astTransformers: {
before: ['my-custom-transformer'],
transform: {
'<regex_match_files>': [
'ts-jest',
{
astTransformers: {
before: ['my-custom-transformer'],
},
},
},
],
},
}
```
Expand All @@ -35,12 +38,15 @@ module.exports = {
{
// [...]
"jest": {
"globals": {
"ts-jest": {
"astTransformers": {
"before": ["my-custom-transformer"]
"transform": {
"<regex_match_files>": [
"ts-jest",
{
"astTransformers": {
"before": ["my-custom-transformer"]
}
}
}
]
}
}
}
Expand All @@ -52,17 +58,20 @@ module.exports = {
// jest.config.js
module.exports = {
// [...]
globals: {
'ts-jest': {
astTransformers: {
before: [
{
path: 'my-custom-transformer-that-needs-extra-opts',
options: {}, // extra options to pass to transformers here
},
],
transform: {
'<regex_match_files>': [
'ts-jest',
{
astTransformers: {
before: [
{
path: 'my-custom-transformer-that-needs-extra-opts',
options: {}, // extra options to pass to transformers here
},
],
},
},
},
],
},
}
```
Expand All @@ -72,17 +81,20 @@ module.exports = {
{
// [...]
"jest": {
"globals": {
"ts-jest": {
"astTransformers": {
"before": [
{
"path": "my-custom-transformer-that-needs-extra-opts",
"options": {} // extra options to pass to transformers here
}
]
"transform": {
"<regex_match_files>": [
"ts-jest",
{
"astTransformers": {
"before": [
{
"path": "my-custom-transformer-that-needs-extra-opts",
"options": {} // extra options to pass to transformers here
}
]
}
}
}
]
}
}
}
Expand Down
85 changes: 53 additions & 32 deletions website/docs/getting-started/options/babelConfig.md
Expand Up @@ -18,10 +18,13 @@ The option is `babelConfig` and it works pretty much as the `tsconfig` option, e
// jest.config.js
module.exports = {
// [...]
globals: {
'ts-jest': {
babelConfig: true,
},
transform: {
'<regex_match_files>': [
'ts-jest',
{
babelConfig: true,
},
],
},
}
```
Expand All @@ -31,10 +34,13 @@ module.exports = {
{
// [...]
"jest": {
"globals": {
"ts-jest": {
"babelConfig": true
}
"transform": {
"<regex_match_files>": [
"ts-jest",
{
"babelConfig": true
}
]
}
}
}
Expand All @@ -48,10 +54,13 @@ The path should be relative to the current working directory where you start Jes
// jest.config.js
module.exports = {
// [...]
globals: {
'ts-jest': {
babelConfig: 'babelrc.test.js',
},
transform: {
'<regex_match_files>': [
'ts-jest',
{
babelConfig: 'babelrc.test.js',
},
],
},
}
```
Expand All @@ -60,10 +69,13 @@ module.exports = {
// OR jest.config.js with require for babelrc
module.exports = {
// [...]
globals: {
'ts-jest': {
babelConfig: require('./babelrc.test.js'),
},
transform: {
'<regex_match_files>': [
'ts-jest',
{
babelConfig: require('./babelrc.test.js'),
},
],
},
}
```
Expand All @@ -73,10 +85,13 @@ module.exports = {
{
// [...]
"jest": {
"globals": {
"ts-jest": {
"babelConfig": "babelrc.test.js"
}
"transform": {
"<regex_match_files>": [
"ts-jest",
{
"babelConfig": "babelrc.test.js"
}
]
}
}
}
Expand All @@ -90,13 +105,16 @@ Refer to the [Babel options](https://babeljs.io/docs/en/next/options) to know wh
// jest.config.js
module.exports = {
// [...]
globals: {
'ts-jest': {
babelConfig: {
comments: false,
plugins: ['@babel/plugin-transform-for-of'],
transform: {
'<regex_match_files>': [
'ts-jest',
{
babelConfig: {
comments: false,
plugins: ['@babel/plugin-transform-for-of'],
},
},
},
],
},
}
```
Expand All @@ -106,13 +124,16 @@ module.exports = {
{
// [...]
"jest": {
"globals": {
"ts-jest": {
"babelConfig": {
"comments": false,
"plugins": ["@babel/plugin-transform-for-of"]
"transform": {
"<regex_match_files>": [
"ts-jest",
{
"babelConfig": {
"comments": false,
"plugins": ["@babel/plugin-transform-for-of"]
}
}
}
]
}
}
}
Expand Down
22 changes: 14 additions & 8 deletions website/docs/getting-started/options/compiler.md
Expand Up @@ -15,10 +15,13 @@ If you use a custom compiler, such as `ttypescript`, make sure its API is the sa
// jest.config.js
module.exports = {
// [...]
globals: {
'ts-jest': {
compiler: 'ttypescript',
},
transform: {
'<regex_match_files': [
'ts-jest',
{
compiler: 'ttypescript',
},
],
},
}
```
Expand All @@ -28,10 +31,13 @@ module.exports = {
{
// [...]
"jest": {
"globals": {
"ts-jest": {
"compiler": "ttypescript"
}
"transform": {
"<regex_match_files>": [
"ts-jest",
{
"compiler": "ttypescript"
}
]
}
}
}
Expand Down

0 comments on commit 4ebacd7

Please sign in to comment.