UNPKG

6.81 kBTypeScriptView Raw
1import type { TransformedSource, TransformOptions } from '@jest/transform';
2import type { Config } from '@jest/types';
3import type * as _babel from 'babel__core';
4import type * as _ts from 'typescript';
5import type { ConfigSet } from './legacy/config/config-set';
6import type { RawCompilerOptions } from './raw-compiler-options';
7declare module '@jest/types' {
8 namespace Config {
9 interface ConfigGlobals {
10 /**
11 * strangely `@ts-expect-error` doesn't work in this case when running
12 * `npm run build` vs `npm run pretest`
13 */
14 'ts-jest'?: TsJestGlobalOptions;
15 }
16 }
17}
18export type TTypeScript = typeof _ts;
19/**
20 * Don't mark as internal because it is used in TsJestGlobalOptions which is an exposed type
21 */
22export type BabelConfig = _babel.TransformOptions;
23export interface AstTransformer<T = Record<string, unknown>> {
24 path: string;
25 options?: T;
26}
27export interface ConfigCustomTransformer {
28 before?: Array<string | AstTransformer>;
29 after?: Array<string | AstTransformer>;
30 afterDeclarations?: Array<string | AstTransformer>;
31}
32/**
33 * @deprecated use `TsJestTransformerOptions` instead
34 */
35export interface TsJestGlobalOptions {
36 /**
37 * Compiler options. It can be:
38 * - `true` (or `undefined`, it's the default): use default tsconfig file
39 * - `false`: do NOT use default config file
40 * - `path/to/tsconfig.json`: path to a specific tsconfig file (<rootDir> can be used)
41 * - `{...}`: an object with inline compiler options
42 *
43 * @default undefined uses the default tsconfig file
44 */
45 tsconfig?: boolean | string | RawCompilerOptions;
46 /**
47 * Compiles files as isolated modules (disables some features and type-checking)
48 *
49 * @default undefined (disabled)
50 */
51 isolatedModules?: boolean;
52 /**
53 * Compiler to use
54 *
55 * @default 'typescript'
56 */
57 compiler?: 'typescript' | 'ttypescript' | string;
58 /**
59 * Custom transformers (mostly used by jest presets)
60 */
61 astTransformers?: ConfigCustomTransformer;
62 /**
63 * TS diagnostics - less to be reported if `isolatedModules` is `true`. It can be:
64 * - `true` (or `undefined`, it's the default): show all diagnostics
65 * - `false`: hide diagnostics of all files (kind of useless)
66 * - `{...}`: an inline object with fine grained settings
67 *
68 * @default undefined shows all diagnostics
69 */
70 diagnostics?: boolean | {
71 /**
72 * Enables colorful and pretty output of errors
73 *
74 * @default undefined (enabled)
75 */
76 pretty?: boolean;
77 /**
78 * List of TypeScript diagnostic error codes to ignore
79 * [here](https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json).
80 *
81 * @see https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json
82 * @default [6059,18002,18003]
83 */
84 ignoreCodes?: number | string | Array<number | string>;
85 /**
86 * If specified, diagnostics of source files which path **matches** will be ignored
87 */
88 exclude?: string[];
89 /**
90 * Logs TypeScript errors to stderr instead of throwing exceptions
91 *
92 * @default undefined (disabled)
93 */
94 warnOnly?: boolean;
95 };
96 /**
97 * Babel config. It can be:
98 * - `false` (or `undefined`, it's the default): do NOT use babel
99 * - `true`: use babel using default babelrc file
100 * - `path/to/.babelrc`: path to a babelrc file (<rootDir> can be used)
101 * - `{...}`: an object with inline babel options
102 *
103 * @default undefined does NOT use babel
104 */
105 babelConfig?: boolean | string | BabelConfig;
106 /**
107 * Kept for backward compatibility to handle __TRANSFORM_HTML__
108 * Any file which will match this regex will be transpiled as a module
109 * exporting the content of the file as a string
110 */
111 stringifyContentPathRegex?: string | RegExp;
112 /**
113 * Tell `ts-jest` to transform codes to ESM format. This only works in combination with `jest-runtime` ESM option
114 * `supportsStaticESM` true which is passed into Jest transformer
115 */
116 useESM?: boolean;
117}
118/**
119 * For transformers which extends `ts-jest`
120 * @deprecated use `JestConfigWithTsJest` instead
121 */
122export interface ProjectConfigTsJest extends Config.ProjectConfig {
123 globals: GlobalConfigTsJest;
124}
125/**
126 * @deprecated use `JestConfigWithTsJest` instead
127 */
128export interface TransformOptionsTsJest<TransformerConfig = unknown> extends TransformOptions<TransformerConfig> {
129 config: Config.ProjectConfig;
130}
131/**
132 * For typings in `jest.config.ts`
133 * @deprecated use `JestConfigWithTsJest` instead
134 */
135export interface GlobalConfigTsJest extends Config.ConfigGlobals {
136 'ts-jest'?: TsJestGlobalOptions;
137}
138/**
139 * @deprecated use `JestConfigWithTsJest` instead
140 */
141export interface InitialOptionsTsJest extends Config.InitialOptions {
142 globals?: GlobalConfigTsJest;
143}
144export type TsJestTransformerOptions = TsJestGlobalOptions;
145export type TsJestTransformOptions = TransformOptions<TsJestTransformerOptions>;
146export interface JestConfigWithTsJest extends Omit<Config.InitialOptions, 'transform'> {
147 transform?: {
148 [regex: string]: 'ts-jest' | 'ts-jest/legacy' | ['ts-jest', TsJestTransformerOptions] | ['ts-jest/legacy', TsJestTransformerOptions] | string | Config.TransformerConfig;
149 };
150}
151export type TsJestPresets = Pick<JestConfigWithTsJest, 'extensionsToTreatAsEsm' | 'moduleFileExtensions' | 'transform' | 'testMatch'>;
152export type StringMap = Map<string, string>;
153export interface DepGraphInfo {
154 fileContent: string;
155 resolvedModuleNames: string[];
156}
157export interface TsJestCompileOptions {
158 depGraphs: Map<string, DepGraphInfo>;
159 watchMode: boolean;
160 supportsStaticESM: boolean;
161}
162export interface CompiledOutput extends TransformedSource {
163 diagnostics?: _ts.Diagnostic[];
164}
165export interface CompilerInstance {
166 getResolvedModules(fileContent: string, fileName: string, runtimeCacheFS: StringMap): string[];
167 getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): CompiledOutput;
168}
169export interface TsCompilerInstance extends CompilerInstance {
170 configSet: ConfigSet;
171 program: _ts.Program | undefined;
172}
173export interface AstTransformerDesc<T = Record<string, unknown>> {
174 name: string;
175 version: number;
176 factory(tsCompiler: TsCompilerInstance, opts?: T): _ts.TransformerFactory<_ts.SourceFile> | _ts.TransformerFactory<_ts.Bundle | _ts.SourceFile>;
177 options?: T;
178}
179export interface TsJestAstTransformer {
180 before: AstTransformerDesc[];
181 after: AstTransformerDesc[];
182 afterDeclarations: AstTransformerDesc[];
183}