UNPKG

3.36 kBTypeScriptView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7import type { RawSourceMap } from 'source-map';
8import type { Config, TransformTypes } from '@jest/types';
9export interface ShouldInstrumentOptions extends Pick<Config.GlobalConfig, 'collectCoverage' | 'collectCoverageFrom' | 'collectCoverageOnlyFrom' | 'coverageProvider'> {
10 changedFiles?: Set<Config.Path>;
11 sourcesRelatedToTestsInChangedFiles?: Set<Config.Path>;
12}
13export interface Options extends ShouldInstrumentOptions, CallerTransformOptions {
14 isInternalModule?: boolean;
15}
16interface FixedRawSourceMap extends Omit<RawSourceMap, 'version'> {
17 version: number;
18}
19export declare type TransformedSource = {
20 code: string;
21 map?: FixedRawSourceMap | string | null;
22} | string;
23export declare type TransformResult = TransformTypes.TransformResult;
24export interface CallerTransformOptions {
25 supportsDynamicImport: boolean;
26 supportsExportNamespaceFrom: boolean;
27 supportsStaticESM: boolean;
28 supportsTopLevelAwait: boolean;
29}
30export interface ReducedTransformOptions extends CallerTransformOptions {
31 instrument: boolean;
32}
33export interface RequireAndTranspileModuleOptions extends ReducedTransformOptions {
34 applyInteropRequireDefault: boolean;
35}
36export declare type StringMap = Map<string, string>;
37export interface TransformOptions<OptionType = unknown> extends ReducedTransformOptions {
38 /** a cached file system which is used in jest-runtime - useful to improve performance */
39 cacheFS: StringMap;
40 config: Config.ProjectConfig;
41 /** A stringified version of the configuration - useful in cache busting */
42 configString: string;
43 /** the options passed through Jest's config by the user */
44 transformerConfig: OptionType;
45}
46export interface SyncTransformer<OptionType = unknown> {
47 canInstrument?: boolean;
48 createTransformer?: (options?: OptionType) => SyncTransformer<OptionType>;
49 getCacheKey?: (sourceText: string, sourcePath: Config.Path, options: TransformOptions<OptionType>) => string;
50 getCacheKeyAsync?: (sourceText: string, sourcePath: Config.Path, options: TransformOptions<OptionType>) => Promise<string>;
51 process: (sourceText: string, sourcePath: Config.Path, options: TransformOptions<OptionType>) => TransformedSource;
52 processAsync?: (sourceText: string, sourcePath: Config.Path, options: TransformOptions<OptionType>) => Promise<TransformedSource>;
53}
54export interface AsyncTransformer<OptionType = unknown> {
55 canInstrument?: boolean;
56 createTransformer?: (options?: OptionType) => AsyncTransformer<OptionType>;
57 getCacheKey?: (sourceText: string, sourcePath: Config.Path, options: TransformOptions<OptionType>) => string;
58 getCacheKeyAsync?: (sourceText: string, sourcePath: Config.Path, options: TransformOptions<OptionType>) => Promise<string>;
59 process?: (sourceText: string, sourcePath: Config.Path, options: TransformOptions<OptionType>) => TransformedSource;
60 processAsync: (sourceText: string, sourcePath: Config.Path, options: TransformOptions<OptionType>) => Promise<TransformedSource>;
61}
62export declare type Transformer<OptionType = unknown> = SyncTransformer<OptionType> | AsyncTransformer<OptionType>;
63export {};