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