eslint-plugin-traceability 1.8.0 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -5
- package/README.md +28 -29
- package/SECURITY.md +135 -0
- package/lib/src/index.d.ts +6 -35
- package/lib/src/index.js +8 -5
- package/lib/src/maintenance/cli.js +12 -16
- package/lib/src/maintenance/detect.js +28 -1
- package/lib/src/rules/helpers/require-story-io.d.ts +2 -2
- package/lib/src/rules/helpers/require-story-io.js +13 -13
- package/lib/src/rules/helpers/valid-annotation-format-internal.d.ts +2 -2
- package/lib/src/rules/helpers/valid-annotation-format-internal.js +3 -3
- package/lib/src/rules/helpers/valid-annotation-utils.d.ts +5 -0
- package/lib/src/rules/helpers/valid-annotation-utils.js +43 -5
- package/lib/src/rules/helpers/valid-implements-utils.d.ts +11 -11
- package/lib/src/rules/helpers/valid-implements-utils.js +11 -11
- package/lib/src/rules/helpers/valid-story-reference-helpers.js +19 -0
- package/lib/src/rules/prefer-implements-annotation.d.ts +7 -7
- package/lib/src/rules/prefer-implements-annotation.js +21 -21
- package/lib/src/rules/valid-annotation-format.js +50 -24
- package/lib/src/rules/valid-req-reference.js +9 -9
- package/lib/src/utils/annotation-checker.js +3 -1
- package/lib/src/utils/reqAnnotationDetection.d.ts +2 -2
- package/lib/src/utils/reqAnnotationDetection.js +28 -28
- package/lib/tests/config/flat-config-presets-integration.test.d.ts +1 -0
- package/lib/tests/config/flat-config-presets-integration.test.js +75 -0
- package/lib/tests/maintenance/batch.test.js +11 -11
- package/lib/tests/maintenance/cli.test.js +34 -27
- package/lib/tests/maintenance/report.test.js +7 -7
- package/lib/tests/plugin-default-export-and-configs.test.js +0 -2
- package/lib/tests/rules/prefer-implements-annotation.test.js +48 -15
- package/lib/tests/rules/require-branch-annotation.test.js +15 -36
- package/lib/tests/rules/require-req-annotation.test.js +31 -104
- package/lib/tests/rules/require-story-annotation.test.js +3 -3
- package/lib/tests/rules/require-story-io-behavior.test.js +2 -7
- package/lib/tests/rules/require-story-io.edgecases.test.js +2 -7
- package/lib/tests/rules/require-story-visitors-edgecases.test.js +8 -8
- package/lib/tests/rules/valid-annotation-format.test.js +23 -23
- package/lib/tests/rules/valid-req-reference.test.js +9 -9
- package/lib/tests/rules/valid-story-reference.test.js +4 -43
- package/lib/tests/utils/annotation-checker.test.js +2 -6
- package/lib/tests/utils/fsTestHelpers.d.ts +7 -0
- package/lib/tests/utils/fsTestHelpers.js +26 -0
- package/lib/tests/utils/ioTestHelpers.d.ts +7 -0
- package/lib/tests/utils/ioTestHelpers.js +24 -0
- package/lib/tests/utils/temp-dir-helpers.d.ts +14 -0
- package/lib/tests/utils/temp-dir-helpers.js +61 -0
- package/package.json +8 -7
- package/user-docs/api-reference.md +37 -20
- package/user-docs/eslint-9-setup-guide.md +89 -6
- package/user-docs/migration-guide.md +37 -21
- package/docs/ci-cd-pipeline.md +0 -224
- package/docs/cli-integration.md +0 -22
- package/docs/code-quality-refactor-opportunities-2025-12-03.md +0 -78
- package/docs/config-presets.md +0 -38
- package/docs/conventional-commits-guide.md +0 -185
- package/docs/custom-rules-development-guide.md +0 -659
- package/docs/decisions/0001-allow-dynamic-require-for-built-plugins.md +0 -26
- package/docs/decisions/001-typescript-for-eslint-plugin.accepted.md +0 -111
- package/docs/decisions/002-jest-for-eslint-testing.accepted.md +0 -137
- package/docs/decisions/003-code-quality-ratcheting-plan.md +0 -48
- package/docs/decisions/004-automated-version-bumping-for-ci-cd.md +0 -196
- package/docs/decisions/005-github-actions-validation-tooling.accepted.md +0 -144
- package/docs/decisions/006-semantic-release-for-automated-publishing.accepted.md +0 -227
- package/docs/decisions/007-github-releases-over-changelog.accepted.md +0 -216
- package/docs/decisions/008-ci-audit-flags.accepted.md +0 -60
- package/docs/decisions/009-security-focused-lint-rules.accepted.md +0 -64
- package/docs/decisions/010-implements-annotation-for-multi-story-requirements.proposed.md +0 -184
- package/docs/decisions/adr-0001-console-usage-for-cli-guards.md +0 -190
- package/docs/decisions/adr-accept-dev-dep-risk-glob.md +0 -40
- package/docs/decisions/adr-commit-branch-tests.md +0 -54
- package/docs/decisions/adr-maintenance-cli-interface.md +0 -140
- package/docs/decisions/adr-pre-push-parity.md +0 -112
- package/docs/decisions/code-quality-ratcheting-plan.md +0 -53
- package/docs/dependency-health.md +0 -238
- package/docs/eslint-9-setup-guide.md +0 -517
- package/docs/eslint-plugin-development-guide.md +0 -487
- package/docs/functionality-coverage-2025-12-03.md +0 -250
- package/docs/jest-testing-guide.md +0 -100
- package/docs/rules/prefer-implements-annotation.md +0 -219
- package/docs/rules/require-branch-annotation.md +0 -71
- package/docs/rules/require-req-annotation.md +0 -203
- package/docs/rules/require-story-annotation.md +0 -159
- package/docs/rules/valid-annotation-format.md +0 -418
- package/docs/rules/valid-req-reference.md +0 -153
- package/docs/rules/valid-story-reference.md +0 -120
- package/docs/security-incidents/2025-11-17-glob-cli-incident.md +0 -45
- package/docs/security-incidents/2025-11-18-brace-expansion-redos.md +0 -45
- package/docs/security-incidents/2025-11-18-bundled-dev-deps-accepted-risk.md +0 -93
- package/docs/security-incidents/2025-11-18-tar-race-condition.md +0 -43
- package/docs/security-incidents/2025-12-03-dependency-health-review.md +0 -58
- package/docs/security-incidents/SECURITY-INCIDENT-2025-11-18-semantic-release-bundled-npm.known-error.md +0 -104
- package/docs/security-incidents/SECURITY-INCIDENT-TEMPLATE.md +0 -37
- package/docs/security-incidents/dependency-override-rationale.md +0 -57
- package/docs/security-incidents/dev-deps-high.json +0 -116
- package/docs/security-incidents/handling-procedure.md +0 -54
- package/docs/stories/001.0-DEV-PLUGIN-SETUP.story.md +0 -92
- package/docs/stories/002.0-DEV-ESLINT-CONFIG.story.md +0 -82
- package/docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md +0 -112
- package/docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md +0 -153
- package/docs/stories/005.0-DEV-ANNOTATION-VALIDATION.story.md +0 -138
- package/docs/stories/006.0-DEV-FILE-VALIDATION.story.md +0 -144
- package/docs/stories/007.0-DEV-ERROR-REPORTING.story.md +0 -163
- package/docs/stories/008.0-DEV-AUTO-FIX.story.md +0 -150
- package/docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md +0 -117
- package/docs/stories/010.0-DEV-DEEP-VALIDATION.story.md +0 -124
- package/docs/stories/010.1-DEV-CONFIGURABLE-PATTERNS.story.md +0 -149
- package/docs/stories/010.2-DEV-MULTI-STORY-SUPPORT.story.md +0 -216
- package/docs/stories/010.3-DEV-MIGRATE-TO-IMPLEMENTS.story.md +0 -236
- package/docs/stories/developer-story.map.md +0 -120
- package/docs/ts-jest-presets-guide.md +0 -548
|
@@ -1,548 +0,0 @@
|
|
|
1
|
-
# ts-jest Presets Guide
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
In Jest, presets are pre-defined configurations that help streamline and standardize the process of setting up testing environments. They allow developers to quickly configure Jest with specific transformers, file extensions, and other options.
|
|
6
|
-
|
|
7
|
-
`ts-jest` provides very opinionated presets based on what has been found to be useful in practice.
|
|
8
|
-
|
|
9
|
-
> **IMPORTANT**: The current best practice for using presets is to call one of the utility functions below to create (and optionally extend) presets. Legacy presets are listed at the bottom of this page.
|
|
10
|
-
|
|
11
|
-
## Available Preset Functions
|
|
12
|
-
|
|
13
|
-
`ts-jest` provides the following utility functions to create presets:
|
|
14
|
-
|
|
15
|
-
- `createDefaultPreset(options)`
|
|
16
|
-
- `createDefaultLegacyPreset(options)`
|
|
17
|
-
- `createDefaultEsmPreset(options)`
|
|
18
|
-
- `createDefaultLegacyEsmPreset(options)`
|
|
19
|
-
- `createJsWithTsPreset(options)`
|
|
20
|
-
- `createJsWithTsLegacyPreset(options)`
|
|
21
|
-
- `createJsWithTsEsmPreset(options)`
|
|
22
|
-
- `createJsWithTsEsmLegacyPreset(options)`
|
|
23
|
-
- `createJsWithBabelPreset(options)`
|
|
24
|
-
- `createJsWithBabelLegacyPreset(options)`
|
|
25
|
-
- `createJsWithBabelEsmPreset(options)`
|
|
26
|
-
- `createJsWithBabelEsmLegacyPreset(options)`
|
|
27
|
-
|
|
28
|
-
## Preset Functions Reference
|
|
29
|
-
|
|
30
|
-
### `createDefaultPreset(options)`
|
|
31
|
-
|
|
32
|
-
Create a configuration to process TypeScript files (`.ts`/`.tsx`).
|
|
33
|
-
|
|
34
|
-
#### Parameters
|
|
35
|
-
|
|
36
|
-
- `options` (OPTIONAL)
|
|
37
|
-
- `tsconfig`: see [tsconfig options page](https://kulshekhar.github.io/ts-jest/docs/getting-started/options/tsconfig)
|
|
38
|
-
- `isolatedModules`: see [isolatedModules options page](https://kulshekhar.github.io/ts-jest/docs/getting-started/options/isolatedModules)
|
|
39
|
-
- `compiler`: see [compiler options page](https://kulshekhar.github.io/ts-jest/docs/getting-started/options/compiler)
|
|
40
|
-
- `astTransformers`: see [astTransformers options page](https://kulshekhar.github.io/ts-jest/docs/getting-started/options/astTransformers)
|
|
41
|
-
- `diagnostics`: see [diagnostics options page](https://kulshekhar.github.io/ts-jest/docs/getting-started/options/diagnostics)
|
|
42
|
-
- `stringifyContentPathRegex`: see [stringifyContentPathRegex options page](https://kulshekhar.github.io/ts-jest/docs/getting-started/options/stringifyContentPathRegex)
|
|
43
|
-
|
|
44
|
-
#### Returns
|
|
45
|
-
|
|
46
|
-
An object containing Jest's `transform` property:
|
|
47
|
-
|
|
48
|
-
```typescript
|
|
49
|
-
export type DefaultPreset = {
|
|
50
|
-
transform: {
|
|
51
|
-
"^.+.tsx?$": ["ts-jest", TsJestTransformerOptions];
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
#### Example
|
|
57
|
-
|
|
58
|
-
```typescript
|
|
59
|
-
// jest.config.ts
|
|
60
|
-
import { createDefaultPreset, type JestConfigWithTsJest } from "ts-jest";
|
|
61
|
-
|
|
62
|
-
const presetConfig = createDefaultPreset({
|
|
63
|
-
//...options
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const jestConfig: JestConfigWithTsJest = {
|
|
67
|
-
...presetConfig,
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export default jestConfig;
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### `createDefaultLegacyPreset(options)`
|
|
74
|
-
|
|
75
|
-
Create a LEGACY configuration to process TypeScript files (`.ts`, `.tsx`).
|
|
76
|
-
|
|
77
|
-
#### Parameters
|
|
78
|
-
|
|
79
|
-
Same as `createDefaultPreset(options)`.
|
|
80
|
-
|
|
81
|
-
#### Returns
|
|
82
|
-
|
|
83
|
-
```typescript
|
|
84
|
-
export type DefaultPreset = {
|
|
85
|
-
transform: {
|
|
86
|
-
"^.+\\.tsx?$": ["ts-jest/legacy", TsJestTransformerOptions];
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
#### Example
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
// jest.config.ts
|
|
95
|
-
import { createDefaultLegacyPreset, type JestConfigWithTsJest } from "ts-jest";
|
|
96
|
-
|
|
97
|
-
const presetConfig = createDefaultLegacyPreset({
|
|
98
|
-
//...options
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
const jestConfig: JestConfigWithTsJest = {
|
|
102
|
-
...presetConfig,
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export default jestConfig;
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
### `createDefaultEsmPreset(options)`
|
|
109
|
-
|
|
110
|
-
Create an ESM configuration to process TypeScript files (`.ts`/`.mts`/`.tsx`/`.mtsx`).
|
|
111
|
-
|
|
112
|
-
#### Parameters
|
|
113
|
-
|
|
114
|
-
Same as `createDefaultPreset(options)`.
|
|
115
|
-
|
|
116
|
-
#### Returns
|
|
117
|
-
|
|
118
|
-
```typescript
|
|
119
|
-
export type DefaultEsmPreset = {
|
|
120
|
-
extensionsToTreatAsEsm: string[];
|
|
121
|
-
transform: {
|
|
122
|
-
"^.+\\.m?tsx?$": ["ts-jest", TsJestTransformerOptions];
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
#### Example
|
|
128
|
-
|
|
129
|
-
```typescript
|
|
130
|
-
// jest.config.ts
|
|
131
|
-
import { createDefaultEsmPreset, type JestConfigWithTsJest } from "ts-jest";
|
|
132
|
-
|
|
133
|
-
const presetConfig = createDefaultEsmPreset({
|
|
134
|
-
//...options
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
const jestConfig: JestConfigWithTsJest = {
|
|
138
|
-
...presetConfig,
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
export default jestConfig;
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
### `createDefaultLegacyEsmPreset(options)`
|
|
145
|
-
|
|
146
|
-
Create a LEGACY ESM configuration to process TypeScript files (`.ts`/`.mts`/`.tsx`/`.mtsx`).
|
|
147
|
-
|
|
148
|
-
#### Parameters
|
|
149
|
-
|
|
150
|
-
Same as `createDefaultPreset(options)`.
|
|
151
|
-
|
|
152
|
-
#### Returns
|
|
153
|
-
|
|
154
|
-
```typescript
|
|
155
|
-
export type DefaultEsmPreset = {
|
|
156
|
-
extensionsToTreatAsEsm: string[];
|
|
157
|
-
transform: {
|
|
158
|
-
"^.+\\.m?tsx?$": ["ts-jest/legacy", TsJestTransformerOptions];
|
|
159
|
-
};
|
|
160
|
-
};
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
#### Example
|
|
164
|
-
|
|
165
|
-
```typescript
|
|
166
|
-
// jest.config.ts
|
|
167
|
-
import {
|
|
168
|
-
createDefaultLegacyEsmPreset,
|
|
169
|
-
type JestConfigWithTsJest,
|
|
170
|
-
} from "ts-jest";
|
|
171
|
-
|
|
172
|
-
const presetConfig = createDefaultLegacyEsmPreset({
|
|
173
|
-
//...options
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
const jestConfig: JestConfigWithTsJest = {
|
|
177
|
-
...presetConfig,
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
export default jestConfig;
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
### `createJsWithTsPreset(options)`
|
|
184
|
-
|
|
185
|
-
Create a configuration to process JavaScript/TypeScript files (`.js`/`.jsx`/`.ts`/`.tsx`).
|
|
186
|
-
|
|
187
|
-
**Note**: You'll need to set `allowJs` to `true` in your `tsconfig.json` file.
|
|
188
|
-
|
|
189
|
-
#### Parameters
|
|
190
|
-
|
|
191
|
-
Same as `createDefaultPreset(options)`.
|
|
192
|
-
|
|
193
|
-
#### Returns
|
|
194
|
-
|
|
195
|
-
```typescript
|
|
196
|
-
export type JsWithTsPreset = {
|
|
197
|
-
transform: {
|
|
198
|
-
"^.+\\.[tj]sx?$": ["ts-jest", TsJestTransformerOptions];
|
|
199
|
-
};
|
|
200
|
-
};
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
#### Example
|
|
204
|
-
|
|
205
|
-
```typescript
|
|
206
|
-
// jest.config.ts
|
|
207
|
-
import { createJsWithTsPreset, type JestConfigWithTsJest } from "ts-jest";
|
|
208
|
-
|
|
209
|
-
const presetConfig = createJsWithTsPreset({
|
|
210
|
-
//...options
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
const jestConfig: JestConfigWithTsJest = {
|
|
214
|
-
...presetConfig,
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
export default jestConfig;
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
### `createJsWithTsLegacyPreset(options)`
|
|
221
|
-
|
|
222
|
-
Create a LEGACY configuration to process JavaScript/TypeScript files (`.js`/`.jsx`/`.ts`/`.tsx`).
|
|
223
|
-
|
|
224
|
-
**Note**: You'll need to set `allowJs` to `true` in your `tsconfig.json` file.
|
|
225
|
-
|
|
226
|
-
#### Parameters
|
|
227
|
-
|
|
228
|
-
Same as `createDefaultPreset(options)`.
|
|
229
|
-
|
|
230
|
-
#### Returns
|
|
231
|
-
|
|
232
|
-
```typescript
|
|
233
|
-
export type JsWithTsPreset = {
|
|
234
|
-
transform: {
|
|
235
|
-
"^.+\\.[tj]sx?$": ["ts-jest/legacy", TsJestTransformerOptions];
|
|
236
|
-
};
|
|
237
|
-
};
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
#### Example
|
|
241
|
-
|
|
242
|
-
```typescript
|
|
243
|
-
// jest.config.ts
|
|
244
|
-
import { createJsWithTsLegacyPreset, type JestConfigWithTsJest } from "ts-jest";
|
|
245
|
-
|
|
246
|
-
const presetConfig = createJsWithTsLegacyPreset({
|
|
247
|
-
//...options
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
const jestConfig: JestConfigWithTsJest = {
|
|
251
|
-
...presetConfig,
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
export default jestConfig;
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
### `createJsWithTsEsmPreset(options)`
|
|
258
|
-
|
|
259
|
-
Create an ESM configuration to process JavaScript/TypeScript files (`.js`/`.mjs`/`.jsx`/`.mjsx`/`.ts`/`.mts`/`.tsx`/`.mtsx`).
|
|
260
|
-
|
|
261
|
-
**Note**: You'll need to set `allowJs` to `true` in your `tsconfig.json` file.
|
|
262
|
-
|
|
263
|
-
#### Parameters
|
|
264
|
-
|
|
265
|
-
Same as `createDefaultPreset(options)`.
|
|
266
|
-
|
|
267
|
-
#### Returns
|
|
268
|
-
|
|
269
|
-
```typescript
|
|
270
|
-
export type JsWithTsPreset = {
|
|
271
|
-
transform: {
|
|
272
|
-
"^.+\\.m?[tj]sx?$": ["ts-jest", TsJestTransformerOptions];
|
|
273
|
-
};
|
|
274
|
-
};
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
#### Example
|
|
278
|
-
|
|
279
|
-
```typescript
|
|
280
|
-
// jest.config.ts
|
|
281
|
-
import { createJsWithTsEsmPreset, type JestConfigWithTsJest } from "ts-jest";
|
|
282
|
-
|
|
283
|
-
const presetConfig = createJsWithTsEsmPreset({
|
|
284
|
-
//...options
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
const jestConfig: JestConfigWithTsJest = {
|
|
288
|
-
...presetConfig,
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
export default jestConfig;
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
### `createJsWithTsEsmLegacyPreset(options)`
|
|
295
|
-
|
|
296
|
-
Create a LEGACY ESM configuration to process JavaScript/TypeScript files (`.js`/`.mjs`/`.jsx`/`.mjsx`/`.ts`/`.mts`/`.tsx`/`.mtsx`).
|
|
297
|
-
|
|
298
|
-
**Note**: You'll need to set `allowJs` to `true` in your `tsconfig.json` file.
|
|
299
|
-
|
|
300
|
-
#### Parameters
|
|
301
|
-
|
|
302
|
-
Same as `createDefaultPreset(options)`.
|
|
303
|
-
|
|
304
|
-
#### Returns
|
|
305
|
-
|
|
306
|
-
```typescript
|
|
307
|
-
export type JsWithTsPreset = {
|
|
308
|
-
transform: {
|
|
309
|
-
"^.+\\.m?[tj]sx?$": ["ts-jest/legacy", TsJestTransformerOptions];
|
|
310
|
-
};
|
|
311
|
-
};
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
#### Example
|
|
315
|
-
|
|
316
|
-
```typescript
|
|
317
|
-
// jest.config.ts
|
|
318
|
-
import {
|
|
319
|
-
createJsWithTsEsmLegacyPreset,
|
|
320
|
-
type JestConfigWithTsJest,
|
|
321
|
-
} from "ts-jest";
|
|
322
|
-
|
|
323
|
-
const presetConfig = createJsWithTsEsmLegacyPreset({
|
|
324
|
-
//...options
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
const jestConfig: JestConfigWithTsJest = {
|
|
328
|
-
...presetConfig,
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
export default jestConfig;
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
### `createJsWithBabelPreset(options)`
|
|
335
|
-
|
|
336
|
-
Create a configuration to process JavaScript/TypeScript files (`.js`/`.jsx`/`.ts`/`.tsx`) which uses `babel-jest` to perform additional transformation.
|
|
337
|
-
|
|
338
|
-
#### Parameters
|
|
339
|
-
|
|
340
|
-
- `options` (OPTIONAL)
|
|
341
|
-
- `tsconfig`: see [tsconfig options page](https://kulshekhar.github.io/ts-jest/docs/getting-started/options/tsconfig)
|
|
342
|
-
- `isolatedModules`: see [isolatedModules options page](https://kulshekhar.github.io/ts-jest/docs/getting-started/options/isolatedModules)
|
|
343
|
-
- `compiler`: see [compiler options page](https://kulshekhar.github.io/ts-jest/docs/getting-started/options/compiler)
|
|
344
|
-
- `astTransformers`: see [astTransformers options page](https://kulshekhar.github.io/ts-jest/docs/getting-started/options/astTransformers)
|
|
345
|
-
- `diagnostics`: see [diagnostics options page](https://kulshekhar.github.io/ts-jest/docs/getting-started/options/diagnostics)
|
|
346
|
-
- `babelConfig`: see [babelConfig options page](https://kulshekhar.github.io/ts-jest/docs/getting-started/options/babelConfig)
|
|
347
|
-
- `stringifyContentPathRegex`: see [stringifyContentPathRegex options page](https://kulshekhar.github.io/ts-jest/docs/getting-started/options/stringifyContentPathRegex)
|
|
348
|
-
|
|
349
|
-
#### Returns
|
|
350
|
-
|
|
351
|
-
```typescript
|
|
352
|
-
export type JsWithBabelPreset = {
|
|
353
|
-
transform: {
|
|
354
|
-
"^.+\\.[tj]sx?$": ["ts-jest", TsJestTransformerOptions];
|
|
355
|
-
};
|
|
356
|
-
};
|
|
357
|
-
```
|
|
358
|
-
|
|
359
|
-
#### Example
|
|
360
|
-
|
|
361
|
-
```typescript
|
|
362
|
-
// jest.config.ts
|
|
363
|
-
import { createJsWithBabelPreset, type JestConfigWithTsJest } from "ts-jest";
|
|
364
|
-
|
|
365
|
-
const presetConfig = createJsWithBabelPreset({
|
|
366
|
-
//...options
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
const jestConfig: JestConfigWithTsJest = {
|
|
370
|
-
...presetConfig,
|
|
371
|
-
};
|
|
372
|
-
|
|
373
|
-
export default jestConfig;
|
|
374
|
-
```
|
|
375
|
-
|
|
376
|
-
### `createJsWithBabelLegacyPreset(options)`
|
|
377
|
-
|
|
378
|
-
Create a LEGACY configuration to process JavaScript/TypeScript files (`.js`/`.jsx`/`.ts`/`.tsx`) which uses `babel-jest` to perform additional transformation.
|
|
379
|
-
|
|
380
|
-
#### Parameters
|
|
381
|
-
|
|
382
|
-
Same as `createJsWithBabelPreset(options)`.
|
|
383
|
-
|
|
384
|
-
#### Returns
|
|
385
|
-
|
|
386
|
-
```typescript
|
|
387
|
-
export type JsWithBabelPreset = {
|
|
388
|
-
transform: {
|
|
389
|
-
"^.+\\.[tj]sx?$": ["ts-jest/legacy", TsJestTransformerOptions];
|
|
390
|
-
};
|
|
391
|
-
};
|
|
392
|
-
```
|
|
393
|
-
|
|
394
|
-
#### Example
|
|
395
|
-
|
|
396
|
-
```typescript
|
|
397
|
-
// jest.config.ts
|
|
398
|
-
import {
|
|
399
|
-
createJsWithBabelLegacyPreset,
|
|
400
|
-
type JestConfigWithTsJest,
|
|
401
|
-
} from "ts-jest";
|
|
402
|
-
|
|
403
|
-
const presetConfig = createJsWithBabelLegacyPreset({
|
|
404
|
-
//...options
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
const jestConfig: JestConfigWithTsJest = {
|
|
408
|
-
...presetConfig,
|
|
409
|
-
};
|
|
410
|
-
|
|
411
|
-
export default jestConfig;
|
|
412
|
-
```
|
|
413
|
-
|
|
414
|
-
### `createJsWithBabelEsmPreset(options)`
|
|
415
|
-
|
|
416
|
-
Create an ESM configuration to process JavaScript/TypeScript files (`.js`/`.mjs`/`.jsx`/`.mjsx`/`.ts`/`.mts`/`.tsx`/`.mtsx`) which uses `babel-jest` to perform additional transformation.
|
|
417
|
-
|
|
418
|
-
#### Parameters
|
|
419
|
-
|
|
420
|
-
Same as `createJsWithBabelPreset(options)`.
|
|
421
|
-
|
|
422
|
-
#### Returns
|
|
423
|
-
|
|
424
|
-
```typescript
|
|
425
|
-
export type JsWithBabelPreset = {
|
|
426
|
-
transform: {
|
|
427
|
-
"^.+\\.[tj]sx?$": ["ts-jest", TsJestTransformerOptions];
|
|
428
|
-
};
|
|
429
|
-
};
|
|
430
|
-
```
|
|
431
|
-
|
|
432
|
-
#### Example
|
|
433
|
-
|
|
434
|
-
```typescript
|
|
435
|
-
// jest.config.ts
|
|
436
|
-
import { createJsWithBabelEsmPreset, type JestConfigWithTsJest } from "ts-jest";
|
|
437
|
-
|
|
438
|
-
const presetConfig = createJsWithBabelEsmPreset({
|
|
439
|
-
//...options
|
|
440
|
-
});
|
|
441
|
-
|
|
442
|
-
const jestConfig: JestConfigWithTsJest = {
|
|
443
|
-
...presetConfig,
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
export default jestConfig;
|
|
447
|
-
```
|
|
448
|
-
|
|
449
|
-
### `createJsWithBabelEsmLegacyPreset(options)`
|
|
450
|
-
|
|
451
|
-
Create a LEGACY ESM configuration to process JavaScript/TypeScript files (`.js`/`.mjs`/`.jsx`/`.mjsx`/`.ts`/`.mts`/`.tsx`/`.mtsx`) which uses `babel-jest` to perform additional transformation.
|
|
452
|
-
|
|
453
|
-
#### Parameters
|
|
454
|
-
|
|
455
|
-
Same as `createJsWithBabelPreset(options)`.
|
|
456
|
-
|
|
457
|
-
#### Returns
|
|
458
|
-
|
|
459
|
-
```typescript
|
|
460
|
-
export type JsWithBabelPreset = {
|
|
461
|
-
transform: {
|
|
462
|
-
"^.+\\.[tj]sx?$": ["ts-jest/legacy", TsJestTransformerOptions];
|
|
463
|
-
};
|
|
464
|
-
};
|
|
465
|
-
```
|
|
466
|
-
|
|
467
|
-
#### Example
|
|
468
|
-
|
|
469
|
-
```typescript
|
|
470
|
-
// jest.config.ts
|
|
471
|
-
import {
|
|
472
|
-
createJsWithBabelEsmLegacyPreset,
|
|
473
|
-
type JestConfigWithTsJest,
|
|
474
|
-
} from "ts-jest";
|
|
475
|
-
|
|
476
|
-
const presetConfig = createJsWithBabelEsmLegacyPreset({
|
|
477
|
-
//...options
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
const jestConfig: JestConfigWithTsJest = {
|
|
481
|
-
...presetConfig,
|
|
482
|
-
};
|
|
483
|
-
|
|
484
|
-
export default jestConfig;
|
|
485
|
-
```
|
|
486
|
-
|
|
487
|
-
## Transformer Options Interface
|
|
488
|
-
|
|
489
|
-
All preset functions accept an optional `options` parameter with the following interface:
|
|
490
|
-
|
|
491
|
-
```typescript
|
|
492
|
-
import type { TsConfigJson } from "type-fest";
|
|
493
|
-
|
|
494
|
-
interface TsJestTransformerOptions {
|
|
495
|
-
tsconfig?: boolean | string | TsConfigJson.CompilerOptions;
|
|
496
|
-
isolatedModules?: boolean;
|
|
497
|
-
astTransformers?: ConfigCustomTransformer;
|
|
498
|
-
diagnostics?:
|
|
499
|
-
| boolean
|
|
500
|
-
| {
|
|
501
|
-
pretty?: boolean;
|
|
502
|
-
ignoreCodes?: number | string | Array<number | string>;
|
|
503
|
-
exclude?: string[];
|
|
504
|
-
warnOnly?: boolean;
|
|
505
|
-
};
|
|
506
|
-
babelConfig?: boolean | string | BabelConfig; // Only for Babel presets
|
|
507
|
-
stringifyContentPathRegex?: string | RegExp;
|
|
508
|
-
}
|
|
509
|
-
```
|
|
510
|
-
|
|
511
|
-
## Legacy Presets (Deprecated)
|
|
512
|
-
|
|
513
|
-
> **WARNING**: `ts-jest` DOES NOT RECOMMEND using legacy presets because this approach is not flexible to configure Jest configuration. These legacy presets will be removed in the next major release and users are HIGHLY RECOMMENDED to migrate to use the utility functions above.
|
|
514
|
-
|
|
515
|
-
| Preset | Description |
|
|
516
|
-
| ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
517
|
-
| `ts-jest/presets/default` or `ts-jest` | TypeScript files (`.ts`, `.tsx`) will be transformed by `ts-jest` to CommonJS syntax, leaving JavaScript files (`.js`, `.jsx`) as-is. |
|
|
518
|
-
| `ts-jest/presets/default-legacy` or `ts-jest/legacy` (LEGACY) | TypeScript files (`.ts`, `.tsx`) will be transformed by `ts-jest` to CommonJS syntax, leaving JavaScript files (`.js`, `.jsx`) as-is. |
|
|
519
|
-
| `ts-jest/presets/default-esm` | TypeScript files (`.ts`, `.tsx`) will be transformed by `ts-jest` to ESM syntax, leaving JavaScript files (`.js`, `.jsx`) as-is. |
|
|
520
|
-
| `ts-jest/presets/default-esm-legacy` (LEGACY) | TypeScript files (`.ts`, `.tsx`) will be transformed by `ts-jest` to ESM syntax, leaving JavaScript files (`.js`, `.jsx`) as-is. |
|
|
521
|
-
| `ts-jest/presets/js-with-ts` | TypeScript and JavaScript files (`.ts`, `.tsx`, `.js`, `.jsx`) will be transformed by `ts-jest` to CommonJS syntax. You'll need to set `allowJs` to `true` in your `tsconfig.json` file. |
|
|
522
|
-
| `ts-jest/presets/js-with-ts-legacy` (LEGACY) | TypeScript and JavaScript files (`.ts`, `.tsx`, `.js`, `.jsx`) will be transformed by `ts-jest` to CommonJS syntax. You'll need to set `allowJs` to `true` in your `tsconfig.json` file. |
|
|
523
|
-
| `ts-jest/presets/js-with-ts-esm` | TypeScript and JavaScript files (`.ts`, `.tsx`, `.js`, `.jsx`, `.mjs`) will be transformed by `ts-jest` to ESM syntax. You'll need to set `allowJs` to `true` in your `tsconfig.json` file. |
|
|
524
|
-
| `ts-jest/presets/js-with-ts-esm-legacy` (LEGACY) | TypeScript and JavaScript files (`.ts`, `.tsx`, `.js`, `.jsx`, `.mjs`) will be transformed by `ts-jest` to ESM syntax. You'll need to set `allowJs` to `true` in your `tsconfig.json` file. |
|
|
525
|
-
| `ts-jest/presets/js-with-babel` | TypeScript files (`.ts`, `.tsx`) will be transformed by `ts-jest` to CommonJS syntax, and JavaScript files (`.js`, `.jsx`) will be transformed by `babel-jest`. |
|
|
526
|
-
| `ts-jest/presets/js-with-babel-legacy` (LEGACY) | TypeScript files (`.ts`, `.tsx`) will be transformed by `ts-jest` to CommonJS syntax, and JavaScript files (`.js`, `.jsx`) will be transformed by `babel-jest`. |
|
|
527
|
-
| `ts-jest/presets/js-with-babel-esm` | TypeScript files (`.ts`, `.tsx`) will be transformed by `ts-jest` to ESM syntax, and JavaScript files (`.js`, `.jsx`, `.mjs`) will be transformed by `babel-jest`. |
|
|
528
|
-
| `ts-jest/presets/js-with-babel-esm-legacy` (LEGACY) | TypeScript files (`.ts`, `.tsx`) will be transformed by `ts-jest` to ESM syntax, and JavaScript files (`.js`, `.jsx`, `.mjs`) will be transformed by `babel-jest`. |
|
|
529
|
-
|
|
530
|
-
### Legacy Preset Example
|
|
531
|
-
|
|
532
|
-
```typescript
|
|
533
|
-
// jest.config.ts
|
|
534
|
-
import type { JestConfigWithTsJest } from "ts-jest";
|
|
535
|
-
|
|
536
|
-
const jestConfig: JestConfigWithTsJest = {
|
|
537
|
-
// Replace `<preset_name>` with one of the preset names from the table above
|
|
538
|
-
preset: "<preset_name>",
|
|
539
|
-
};
|
|
540
|
-
|
|
541
|
-
export default jestConfig;
|
|
542
|
-
```
|
|
543
|
-
|
|
544
|
-
## References
|
|
545
|
-
|
|
546
|
-
- [Official ts-jest Presets Documentation](https://kulshekhar.github.io/ts-jest/docs/getting-started/presets)
|
|
547
|
-
- [ts-jest Installation Guide](https://kulshekhar.github.io/ts-jest/docs/getting-started/installation)
|
|
548
|
-
- [ts-jest Options](https://kulshekhar.github.io/ts-jest/docs/getting-started/options)
|