index.d.ts
  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   */
  7  import type { JestEnvironment } from '@jest/environment';
  8  import type * as JestGlobals from '@jest/globals';
  9  import type { SourceMapRegistry } from '@jest/source-map';
 10  import type { V8CoverageResult } from '@jest/test-result';
 11  import { CallerTransformOptions, ShouldInstrumentOptions, shouldInstrument } from '@jest/transform';
 12  import type { Config, Global } from '@jest/types';
 13  import HasteMap = require('jest-haste-map');
 14  import Resolver = require('jest-resolve');
 15  import { options as cliOptions } from './cli/args';
 16  import type { Context as JestContext } from './types';
 17  interface JestGlobals extends Global.TestFrameworkGlobals {
 18      expect: typeof JestGlobals.expect;
 19  }
 20  declare type HasteMapOptions = {
 21      console?: Console;
 22      maxWorkers: number;
 23      resetCache: boolean;
 24      watch?: boolean;
 25      watchman: boolean;
 26  };
 27  interface InternalModuleOptions extends Required<CallerTransformOptions> {
 28      isInternalModule: boolean;
 29  }
 30  declare namespace Runtime {
 31      type Context = JestContext;
 32      type RuntimeType = Runtime;
 33  }
 34  declare class Runtime {
 35      private _cacheFS;
 36      private _config;
 37      private _coverageOptions;
 38      private _currentlyExecutingModulePath;
 39      private _environment;
 40      private _explicitShouldMock;
 41      private _fakeTimersImplementation;
 42      private _internalModuleRegistry;
 43      private _isCurrentlyExecutingManualMock;
 44      private _mainModule;
 45      private _mockFactories;
 46      private _mockMetaDataCache;
 47      private _mockRegistry;
 48      private _isolatedMockRegistry;
 49      private _moduleMocker;
 50      private _isolatedModuleRegistry;
 51      private _moduleRegistry;
 52      private _esmoduleRegistry;
 53      private _testPath;
 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, testPath?: Config.Path);
 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  }
132  export = Runtime;