From 4ebacd7372e2cfb7a3b49bf4e3af0408ff64c1ab Mon Sep 17 00:00:00 2001 From: Ahn <27772165+ahnpnl@users.noreply.github.com> Date: Sun, 28 Aug 2022 20:25:45 +0200 Subject: [PATCH] docs(devs-infra): update docs to reflect transformer config (#3782) --- website/docs/getting-started/options.md | 46 +++++--- .../options/astTransformers.md | 72 +++++++------ .../getting-started/options/babelConfig.md | 85 +++++++++------ .../docs/getting-started/options/compiler.md | 22 ++-- .../getting-started/options/diagnostics.md | 100 +++++++++++------- .../options/isolatedModules.md | 22 ++-- .../options/stringifyContentPathRegex.md | 23 ++-- .../docs/getting-started/options/tsconfig.md | 72 ++++++++----- .../docs/getting-started/options/useESM.md | 22 ++-- website/docs/guides/esm-support.md | 52 +++++---- website/docs/guides/react-native.md | 12 +-- 11 files changed, 325 insertions(+), 203 deletions(-) diff --git a/website/docs/getting-started/options.md b/website/docs/getting-started/options.md index a5c8784da8..4a3b6ce6e3 100644 --- a/website/docs/getting-started/options.md +++ b/website/docs/getting-started/options.md @@ -5,7 +5,7 @@ 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 @@ -13,10 +13,13 @@ or through a `jest.config.js`, or `jest.config.ts` file. { // [...] "jest": { - "globals": { - "ts-jest": { - // ts-jest configuration goes here - } + "transform": { + "": [ + "ts-jest", + { + // ts-jest configuration goes here + } + ] } } } @@ -28,10 +31,13 @@ Or through JavaScript: // jest.config.js module.exports = { // [...] - globals: { - 'ts-jest': { - // ts-jest configuration goes here - }, + transform: { + '': [ + 'ts-jest', + { + // ts-jest configuration goes here + }, + ], }, } ``` @@ -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: { + '': [ + 'ts-jest', + { + // ts-jest configuration goes here and your IDE will suggest which configs when typing + }, + ], }, } ``` @@ -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: { + '': [ + 'ts-jest', + { + // ts-jest configuration goes here + }, + ], }, } export default config diff --git a/website/docs/getting-started/options/astTransformers.md b/website/docs/getting-started/options/astTransformers.md index c3cd3bf08d..1998f7746d 100644 --- a/website/docs/getting-started/options/astTransformers.md +++ b/website/docs/getting-started/options/astTransformers.md @@ -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: { + '': [ + 'ts-jest', + { + astTransformers: { + before: ['my-custom-transformer'], + }, }, - }, + ], }, } ``` @@ -35,12 +38,15 @@ module.exports = { { // [...] "jest": { - "globals": { - "ts-jest": { - "astTransformers": { - "before": ["my-custom-transformer"] + "transform": { + "": [ + "ts-jest", + { + "astTransformers": { + "before": ["my-custom-transformer"] + } } - } + ] } } } @@ -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: { + '': [ + 'ts-jest', + { + astTransformers: { + before: [ + { + path: 'my-custom-transformer-that-needs-extra-opts', + options: {}, // extra options to pass to transformers here + }, + ], + }, }, - }, + ], }, } ``` @@ -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": { + "": [ + "ts-jest", + { + "astTransformers": { + "before": [ + { + "path": "my-custom-transformer-that-needs-extra-opts", + "options": {} // extra options to pass to transformers here + } + ] + } } - } + ] } } } diff --git a/website/docs/getting-started/options/babelConfig.md b/website/docs/getting-started/options/babelConfig.md index 5d128334c9..73a6ee27c4 100644 --- a/website/docs/getting-started/options/babelConfig.md +++ b/website/docs/getting-started/options/babelConfig.md @@ -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: { + '': [ + 'ts-jest', + { + babelConfig: true, + }, + ], }, } ``` @@ -31,10 +34,13 @@ module.exports = { { // [...] "jest": { - "globals": { - "ts-jest": { - "babelConfig": true - } + "transform": { + "": [ + "ts-jest", + { + "babelConfig": true + } + ] } } } @@ -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: { + '': [ + 'ts-jest', + { + babelConfig: 'babelrc.test.js', + }, + ], }, } ``` @@ -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: { + '': [ + 'ts-jest', + { + babelConfig: require('./babelrc.test.js'), + }, + ], }, } ``` @@ -73,10 +85,13 @@ module.exports = { { // [...] "jest": { - "globals": { - "ts-jest": { - "babelConfig": "babelrc.test.js" - } + "transform": { + "": [ + "ts-jest", + { + "babelConfig": "babelrc.test.js" + } + ] } } } @@ -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: { + '': [ + 'ts-jest', + { + babelConfig: { + comments: false, + plugins: ['@babel/plugin-transform-for-of'], + }, }, - }, + ], }, } ``` @@ -106,13 +124,16 @@ module.exports = { { // [...] "jest": { - "globals": { - "ts-jest": { - "babelConfig": { - "comments": false, - "plugins": ["@babel/plugin-transform-for-of"] + "transform": { + "": [ + "ts-jest", + { + "babelConfig": { + "comments": false, + "plugins": ["@babel/plugin-transform-for-of"] + } } - } + ] } } } diff --git a/website/docs/getting-started/options/compiler.md b/website/docs/getting-started/options/compiler.md index dea461e280..0d21700a85 100644 --- a/website/docs/getting-started/options/compiler.md +++ b/website/docs/getting-started/options/compiler.md @@ -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: { + '": [ + "ts-jest", + { + "compiler": "ttypescript" + } + ] } } } diff --git a/website/docs/getting-started/options/diagnostics.md b/website/docs/getting-started/options/diagnostics.md index 27c849fb2c..09958e8e00 100644 --- a/website/docs/getting-started/options/diagnostics.md +++ b/website/docs/getting-started/options/diagnostics.md @@ -35,10 +35,13 @@ The `diagnostics` option's value can also accept an object for more advanced con // jest.config.js module.exports = { // [...] - globals: { - 'ts-jest': { - diagnostics: false, - }, + transform: { + '": [ + "ts-jest", + { + "diagnostics": false + } + ] } } } @@ -67,12 +73,15 @@ Assuming all your test files ends with `.spec.ts` or `.test.ts`, using the follo // jest.config.js module.exports = { // [...] - globals: { - 'ts-jest': { - diagnostics: { - exclude: ['!**/*.(spec|test).ts'], + transform: { + '": [ + "ts-jest", + { + "diagnostics": { + "exclude": ["!**/*.(spec|test).ts"] + } } - } + ] } } } @@ -101,12 +113,15 @@ While some diagnostics are stop-blockers for the compilation, most of them are n // jest.config.js module.exports = { // [...] - globals: { - 'ts-jest': { - diagnostics: { - warnOnly: true, + transform: { + '": [ + "ts-jest", + { + "diagnostics": { + "warnOnly": true + } } - } + ] } } } @@ -140,12 +158,15 @@ All TypeScript error codes can be found [there](https://github.com/Microsoft/Typ // jest.config.js module.exports = { // [...] - globals: { - 'ts-jest': { - diagnostics: { - ignoreCodes: [2571, 6031, 18003], + transform: { + '": [ + "ts-jest", + { + "diagnostics": { + "ignoreCodes": [2571, 6031, 18003] + } } - } + ] } } } diff --git a/website/docs/getting-started/options/isolatedModules.md b/website/docs/getting-started/options/isolatedModules.md index 56c25c1be1..fa74347415 100644 --- a/website/docs/getting-started/options/isolatedModules.md +++ b/website/docs/getting-started/options/isolatedModules.md @@ -16,10 +16,13 @@ Here is how to disable type-checking and compile each file as an isolated module // jest.config.js module.exports = { // [...] - globals: { - 'ts-jest': { - isolatedModules: true, - }, + transform: { + '": [ + "ts-jest", + { + "isolatedModules": true + } + ] } } } diff --git a/website/docs/getting-started/options/stringifyContentPathRegex.md b/website/docs/getting-started/options/stringifyContentPathRegex.md index d65d6b2102..f3302665d0 100644 --- a/website/docs/getting-started/options/stringifyContentPathRegex.md +++ b/website/docs/getting-started/options/stringifyContentPathRegex.md @@ -26,10 +26,13 @@ module.exports = { ...tsjPreset.transform, '\\.html$': 'ts-jest', }, - globals: { - 'ts-jest': { - stringifyContentPathRegex: /\.html$/, - }, + transform: { + '": [ + "ts-jest", + { + "tsconfig": "tsconfig.test.json" + } + ] } } } @@ -49,12 +55,15 @@ It's basically the same object you'd put in your `tsconfig.json`'s `compilerOpti // jest.config.js module.exports = { // [...] - globals: { - 'ts-jest': { - tsconfig: { - importHelpers: true, + transform: { + '": [ + "ts-jest", + { + "tsconfig": { + "importHelpers": true + } } - } + ] } } } @@ -83,10 +95,13 @@ By default `ts-jest` will try to find a `tsconfig.json` in your project. But you // jest.config.js module.exports = { // [...] - globals: { - 'ts-jest': { - tsconfig: false, - }, + transform: { + '": [ + "ts-jest", + { + "tsconfig": { + "tsconfig": false + } + } + ] } } } diff --git a/website/docs/getting-started/options/useESM.md b/website/docs/getting-started/options/useESM.md index 7c0a5eadec..9bd28aa794 100644 --- a/website/docs/getting-started/options/useESM.md +++ b/website/docs/getting-started/options/useESM.md @@ -12,10 +12,13 @@ The default value is **false**, `ts-jest` will transform codes to `CommonJS` syn // jest.config.js module.exports = { // [...] - globals: { - 'ts-jest': { - useESM: true, - }, + transform: { + '": [ + "ts-jest", + { + "useESM": true + } + ] } } } diff --git a/website/docs/guides/esm-support.md b/website/docs/guides/esm-support.md index 42dfe8e532..a36682263d 100644 --- a/website/docs/guides/esm-support.md +++ b/website/docs/guides/esm-support.md @@ -23,14 +23,17 @@ There are also [3 presets](../getting-started/presets.md) to work with ESM. module.exports = { // [...] extensionsToTreatAsEsm: ['.ts'], - globals: { - 'ts-jest': { - useESM: true, - }, - }, moduleNameMapper: { '^(\\.{1,2}/.*)\\.js$': '$1', }, + transform: { + '": [ + "ts-jest", + { + "useESM": true + } + ] } } } @@ -65,14 +71,17 @@ Starting from **v28.0.0**, `ts-jest` will gradually switch to `esbuild`/`swc` to module.exports = { // [...] preset: 'ts-jest/presets/default-esm', // or other ESM presets - globals: { - 'ts-jest': { - useESM: true, - }, - }, moduleNameMapper: { '^(\\.{1,2}/.*)\\.js$': '$1', }, + transform: { + '": [ + "ts-jest", + { + "useESM": true + } + ] } } } diff --git a/website/docs/guides/react-native.md b/website/docs/guides/react-native.md index afcc4cf4f5..bbcf14776e 100644 --- a/website/docs/guides/react-native.md +++ b/website/docs/guides/react-native.md @@ -42,14 +42,14 @@ const { defaults: tsjPreset } = require('ts-jest/presets') module.exports = { preset: 'react-native', - globals: { - 'ts-jest': { - tsconfig: 'tsconfig.spec.json', - }, - }, transform: { '^.+\\.jsx$': 'babel-jest', - '^.+\\.tsx?$': 'ts-jest', + '^.+\\.tsx?$': [ + 'ts-jest', + { + tsconfig: 'tsconfig.spec.json', + }, + ], }, moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], }