UNPKG

5.23 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 { Config, Global } from '@jest/types';
8import type { JestEnvironment } from '@jest/environment';
9import type * as JestGlobals from '@jest/globals';
10import type { SourceMapRegistry } from '@jest/source-map';
11import { ShouldInstrumentOptions, shouldInstrument } from '@jest/transform';
12import type { V8CoverageResult } from '@jest/test-result';
13import HasteMap = require('jest-haste-map');
14import Resolver = require('jest-resolve');
15import type { Context as JestContext } from './types';
16import { options as cliOptions } from './cli/args';
17interface JestGlobals extends Global.TestFrameworkGlobals {
18 expect: typeof JestGlobals.expect;
19}
20declare type HasteMapOptions = {
21 console?: Console;
22 maxWorkers: number;
23 resetCache: boolean;
24 watch?: boolean;
25 watchman: boolean;
26};
27declare type InternalModuleOptions = {
28 isInternalModule: boolean;
29 supportsDynamicImport: boolean;
30 supportsStaticESM: boolean;
31};
32declare namespace Runtime {
33 type Context = JestContext;
34 type RuntimeType = Runtime;
35}
36declare class Runtime {
37 private _cacheFS;
38 private _config;
39 private _coverageOptions;
40 private _currentlyExecutingModulePath;
41 private _environment;
42 private _explicitShouldMock;
43 private _fakeTimersImplementation;
44 private _internalModuleRegistry;
45 private _isCurrentlyExecutingManualMock;
46 private _mockFactories;
47 private _mockMetaDataCache;
48 private _mockRegistry;
49 private _isolatedMockRegistry;
50 private _moduleMocker;
51 private _isolatedModuleRegistry;
52 private _moduleRegistry;
53 private _esmoduleRegistry;
54 private _resolver;
55 private _shouldAutoMock;
56 private _shouldMockModuleCache;
57 private _shouldUnmockTransitiveDependenciesCache;
58 private _sourceMapRegistry;
59 private _scriptTransformer;
60 private _fileTransforms;
61 private _v8CoverageInstrumenter;
62 private _v8CoverageResult;
63 private _transitiveShouldMock;
64 private _unmockList;
65 private _virtualMocks;
66 private _moduleImplementation?;
67 private jestObjectCaches;
68 private jestGlobals?;
69 constructor(config: Config.ProjectConfig, environment: JestEnvironment, resolver: Resolver, cacheFS?: Record<string, string>, coverageOptions?: ShouldInstrumentOptions);
70 static shouldInstrument: typeof shouldInstrument;
71 static createContext(config: Config.ProjectConfig, options: {
72 console?: Console;
73 maxWorkers: number;
74 watch?: boolean;
75 watchman: boolean;
76 }): Promise<JestContext>;
77 static createHasteMap(config: Config.ProjectConfig, options?: HasteMapOptions): HasteMap;
78 static createResolver(config: Config.ProjectConfig, moduleMap: HasteMap.ModuleMap): Resolver;
79 static runCLI(args?: Config.Argv, info?: Array<string>): Promise<void>;
80 static getCLIOptions(): typeof cliOptions;
81 unstable_shouldLoadAsEsm: typeof import("jest-resolve/build/shouldLoadAsEsm").default;
82 private loadEsmModule;
83 private linkModules;
84 unstable_importModule(from: Config.Path, moduleName?: string): Promise<void>;
85 private loadCjsAsEsm;
86 requireModule<T = unknown>(from: Config.Path, moduleName?: string, options?: InternalModuleOptions, isRequireActual?: boolean | null): T;
87 requireInternalModule<T = unknown>(from: Config.Path, to?: string): T;
88 requireActual<T = unknown>(from: Config.Path, moduleName: string): T;
89 requireMock<T = unknown>(from: Config.Path, moduleName: string): T;
90 private _loadModule;
91 private _getFullTransformationOptions;
92 requireModuleOrMock<T = unknown>(from: Config.Path, moduleName: string): T;
93 isolateModules(fn: () => void): void;
94 resetModules(): void;
95 collectV8Coverage(): Promise<void>;
96 stopCollectingV8Coverage(): Promise<void>;
97 getAllCoverageInfoCopy(): JestEnvironment['global']['__coverage__'];
98 getAllV8CoverageInfoCopy(): V8CoverageResult;
99 getSourceMapInfo(_coveredFiles: Set<string>): Record<string, string>;
100 getSourceMaps(): SourceMapRegistry;
101 setMock(from: string, moduleName: string, mockFactory: () => unknown, options?: {
102 virtual?: boolean;
103 }): void;
104 restoreAllMocks(): void;
105 resetAllMocks(): void;
106 clearAllMocks(): void;
107 teardown(): void;
108 private _resolveModule;
109 private _requireResolve;
110 private _requireResolvePaths;
111 private _execModule;
112 private transformFile;
113 private createScriptFromCode;
114 private _requireCoreModule;
115 private _importCoreModule;
116 private _getMockedNativeModule;
117 private _generateMock;
118 private _shouldMock;
119 private _createRequireImplementation;
120 private _createJestObjectFor;
121 private _logFormattedReferenceError;
122 private wrapCodeInModuleWrapper;
123 private constructModuleWrapperStart;
124 private constructInjectedModuleParameters;
125 private handleExecutionError;
126 private getGlobalsForCjs;
127 private getGlobalsForEsm;
128 private getGlobalsFromEnvironment;
129 private readFile;
130 setGlobalsForRuntime(globals: JestGlobals): void;
131}
132export = Runtime;