1 | import type { TransformedSource, TransformOptions } from '@jest/transform';
|
2 | import type { Config } from '@jest/types';
|
3 | import type * as _babel from 'babel__core';
|
4 | import type * as _ts from 'typescript';
|
5 | import { ESM_JS_TRANSFORM_PATTERN, ESM_TS_JS_TRANSFORM_PATTERN, ESM_TS_TRANSFORM_PATTERN, JS_TRANSFORM_PATTERN, TS_JS_TRANSFORM_PATTERN, TS_TRANSFORM_PATTERN } from './constants';
|
6 | import type { ConfigSet } from './legacy/config/config-set';
|
7 | import type { RawCompilerOptions } from './raw-compiler-options';
|
8 | export type TTypeScript = typeof _ts;
|
9 |
|
10 |
|
11 |
|
12 | export type BabelConfig = _babel.TransformOptions;
|
13 | export interface AstTransformer<T = Record<string, unknown>> {
|
14 | path: string;
|
15 | options?: T;
|
16 | }
|
17 | export interface ConfigCustomTransformer {
|
18 | before?: Array<string | AstTransformer>;
|
19 | after?: Array<string | AstTransformer>;
|
20 | afterDeclarations?: Array<string | AstTransformer>;
|
21 | }
|
22 |
|
23 |
|
24 |
|
25 | export interface TsJestGlobalOptions {
|
26 | |
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | tsconfig?: boolean | string | RawCompilerOptions;
|
36 | |
37 |
|
38 |
|
39 |
|
40 |
|
41 | isolatedModules?: boolean;
|
42 | |
43 |
|
44 |
|
45 |
|
46 |
|
47 | compiler?: 'typescript' | 'ttypescript' | string;
|
48 | |
49 |
|
50 |
|
51 | astTransformers?: ConfigCustomTransformer;
|
52 | |
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | diagnostics?: boolean | {
|
61 | |
62 |
|
63 |
|
64 |
|
65 |
|
66 | pretty?: boolean;
|
67 | |
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | ignoreCodes?: number | string | Array<number | string>;
|
75 | |
76 |
|
77 |
|
78 | exclude?: string[];
|
79 | |
80 |
|
81 |
|
82 |
|
83 |
|
84 | warnOnly?: boolean;
|
85 | };
|
86 | |
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | babelConfig?: boolean | string | BabelConfig;
|
96 | |
97 |
|
98 |
|
99 |
|
100 |
|
101 | stringifyContentPathRegex?: string | RegExp;
|
102 | |
103 |
|
104 |
|
105 |
|
106 | useESM?: boolean;
|
107 | }
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | export interface ProjectConfigTsJest extends Config.ProjectConfig {
|
113 | globals: GlobalConfigTsJest;
|
114 | }
|
115 |
|
116 |
|
117 |
|
118 | export interface TransformOptionsTsJest<TransformerConfig = unknown> extends TransformOptions<TransformerConfig> {
|
119 | config: Config.ProjectConfig;
|
120 | }
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | export interface GlobalConfigTsJest extends Config.ConfigGlobals {
|
126 | 'ts-jest'?: TsJestGlobalOptions;
|
127 | }
|
128 |
|
129 |
|
130 |
|
131 | export interface InitialOptionsTsJest extends Config.InitialOptions {
|
132 | globals?: GlobalConfigTsJest;
|
133 | }
|
134 | export type TsJestTransformerOptions = TsJestGlobalOptions;
|
135 | export type TsJestTransformOptions = TransformOptions<TsJestTransformerOptions>;
|
136 | export interface JestConfigWithTsJest extends Omit<Config.InitialOptions, 'transform'> {
|
137 | transform?: {
|
138 | [regex: string]: 'ts-jest' | 'ts-jest/legacy' | ['ts-jest', TsJestTransformerOptions] | ['ts-jest/legacy', TsJestTransformerOptions] | string | Config.TransformerConfig;
|
139 | };
|
140 | }
|
141 | export type StringMap = Map<string, string>;
|
142 | export interface DepGraphInfo {
|
143 | fileContent: string;
|
144 | resolvedModuleNames: string[];
|
145 | }
|
146 | export interface TsJestCompileOptions {
|
147 | depGraphs: Map<string, DepGraphInfo>;
|
148 | watchMode: boolean;
|
149 | supportsStaticESM: boolean;
|
150 | }
|
151 | export interface CompiledOutput extends TransformedSource {
|
152 | diagnostics?: _ts.Diagnostic[];
|
153 | }
|
154 | export interface CompilerInstance {
|
155 | getResolvedModules(fileContent: string, fileName: string, runtimeCacheFS: StringMap): string[];
|
156 | getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): CompiledOutput;
|
157 | }
|
158 | export interface TsCompilerInstance extends CompilerInstance {
|
159 | configSet: ConfigSet;
|
160 | program: _ts.Program | undefined;
|
161 | }
|
162 | export interface AstTransformerDesc<T = Record<string, unknown>> {
|
163 | name: string;
|
164 | version: number;
|
165 | factory(tsCompiler: TsCompilerInstance, opts?: T): _ts.TransformerFactory<_ts.SourceFile> | _ts.TransformerFactory<_ts.Bundle | _ts.SourceFile>;
|
166 | options?: T;
|
167 | }
|
168 | export interface TsJestAstTransformer {
|
169 | before: AstTransformerDesc[];
|
170 | after: AstTransformerDesc[];
|
171 | afterDeclarations: AstTransformerDesc[];
|
172 | }
|
173 |
|
174 |
|
175 |
|
176 | export type TsJestPresets = Pick<JestConfigWithTsJest, 'extensionsToTreatAsEsm' | 'moduleFileExtensions' | 'transform' | 'testMatch'>;
|
177 | export type DefaultTransformOptions = Omit<TsJestTransformerOptions, 'useESM'>;
|
178 | export type DefaultPreset = {
|
179 | transform: {
|
180 | [TS_TRANSFORM_PATTERN]: ['ts-jest', DefaultTransformOptions];
|
181 | };
|
182 | };
|
183 | export type DefaultLegacyPreset = {
|
184 | transform: {
|
185 | [TS_TRANSFORM_PATTERN]: ['ts-jest/legacy', DefaultTransformOptions];
|
186 | };
|
187 | };
|
188 | export type DefaultEsmTransformOptions = Omit<TsJestTransformerOptions, 'useESM'>;
|
189 | export type DefaultEsmPreset = {
|
190 | extensionsToTreatAsEsm: string[];
|
191 | transform: {
|
192 | [ESM_TS_TRANSFORM_PATTERN]: ['ts-jest', {
|
193 | useESM: true;
|
194 | } & DefaultEsmTransformOptions];
|
195 | };
|
196 | };
|
197 | export type DefaultEsmLegacyPreset = {
|
198 | extensionsToTreatAsEsm: string[];
|
199 | transform: {
|
200 | [ESM_TS_TRANSFORM_PATTERN]: ['ts-jest/legacy', {
|
201 | useESM: true;
|
202 | } & DefaultEsmTransformOptions];
|
203 | };
|
204 | };
|
205 | export type JsWithTsTransformOptions = Omit<TsJestTransformerOptions, 'useESM'>;
|
206 | export type JsWithTsPreset = {
|
207 | transform: {
|
208 | [TS_JS_TRANSFORM_PATTERN]: ['ts-jest', JsWithTsTransformOptions];
|
209 | };
|
210 | };
|
211 | export type JsWithTsLegacyPreset = {
|
212 | transform: {
|
213 | [TS_JS_TRANSFORM_PATTERN]: ['ts-jest/legacy', JsWithTsTransformOptions];
|
214 | };
|
215 | };
|
216 | export type JsWithTsEsmTransformOptions = Omit<TsJestTransformerOptions, 'useESM'>;
|
217 | export type JsWithTsEsmPreset = {
|
218 | extensionsToTreatAsEsm: string[];
|
219 | transform: {
|
220 | [ESM_TS_JS_TRANSFORM_PATTERN]: ['ts-jest', {
|
221 | useESM: true;
|
222 | } & JsWithTsEsmTransformOptions];
|
223 | };
|
224 | };
|
225 | export type JsWithTsEsmLegacyPreset = {
|
226 | extensionsToTreatAsEsm: string[];
|
227 | transform: {
|
228 | [ESM_TS_JS_TRANSFORM_PATTERN]: ['ts-jest/legacy', {
|
229 | useESM: true;
|
230 | } & JsWithTsEsmTransformOptions];
|
231 | };
|
232 | };
|
233 | export type JsWithBabelTransformerOptions = Omit<TsJestTransformerOptions, 'useESM'>;
|
234 | export type JsWithBabelPreset = {
|
235 | transform: {
|
236 | [JS_TRANSFORM_PATTERN]: 'babel-jest';
|
237 | [TS_TRANSFORM_PATTERN]: ['ts-jest', JsWithBabelTransformerOptions];
|
238 | };
|
239 | };
|
240 | export type JsWithBabelLegacyPreset = {
|
241 | transform: {
|
242 | [JS_TRANSFORM_PATTERN]: 'babel-jest';
|
243 | [TS_TRANSFORM_PATTERN]: ['ts-jest/legacy', JsWithBabelTransformerOptions];
|
244 | };
|
245 | };
|
246 | export type JsWithBabelEsmTransformOptions = Omit<TsJestTransformerOptions, 'useESM'>;
|
247 | export type JsWithBabelEsmPreset = {
|
248 | extensionsToTreatAsEsm: string[];
|
249 | transform: {
|
250 | [ESM_JS_TRANSFORM_PATTERN]: 'babel-jest';
|
251 | [ESM_TS_TRANSFORM_PATTERN]: ['ts-jest', {
|
252 | useESM: true;
|
253 | } & JsWithBabelEsmTransformOptions];
|
254 | };
|
255 | };
|
256 | export type JsWithBabelEsmLegacyPreset = {
|
257 | extensionsToTreatAsEsm: string[];
|
258 | transform: {
|
259 | [ESM_JS_TRANSFORM_PATTERN]: 'babel-jest';
|
260 | [ESM_TS_TRANSFORM_PATTERN]: ['ts-jest/legacy', {
|
261 | useESM: true;
|
262 | } & JsWithBabelEsmTransformOptions];
|
263 | };
|
264 | };
|
265 | declare module '@jest/types' {
|
266 | namespace Config {
|
267 | interface ConfigGlobals {
|
268 | |
269 |
|
270 |
|
271 |
|
272 | 'ts-jest'?: TsJestTransformerOptions;
|
273 | }
|
274 | }
|
275 | }
|