初始化fy

This commit is contained in:
yziiy
2025-08-11 11:51:38 +08:00
parent 98ce20e897
commit 7e21160e13
19770 changed files with 3108698 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
/**
* 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';
export declare const createOutsideJestVmPath: (path: string) => string;
export declare const decodePossibleOutsideJestVmPath: (outsideJestVmPath: string) => string | undefined;
export declare const findSiblingsWithFileExtension: (moduleFileExtensions: Config.ProjectConfig['moduleFileExtensions'], from: Config.Path, moduleName: string) => string;

View File

@@ -0,0 +1,157 @@
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.findSiblingsWithFileExtension =
exports.decodePossibleOutsideJestVmPath =
exports.createOutsideJestVmPath =
void 0;
function path() {
const data = _interopRequireWildcard(require('path'));
path = function () {
return data;
};
return data;
}
function _glob() {
const data = _interopRequireDefault(require('glob'));
_glob = function () {
return data;
};
return data;
}
function _slash() {
const data = _interopRequireDefault(require('slash'));
_slash = function () {
return data;
};
return data;
}
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {default: obj};
}
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== 'function') return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function (nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interopRequireWildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
return {default: obj};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor =
Object.defineProperty && Object.getOwnPropertyDescriptor;
for (var key in obj) {
if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor
? Object.getOwnPropertyDescriptor(obj, key)
: null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
/**
* 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.
*/
const OUTSIDE_JEST_VM_PROTOCOL = 'jest-main:'; // String manipulation is easier here, fileURLToPath is only in newer Nodes,
// plus setting non-standard protocols on URL objects is difficult.
const createOutsideJestVmPath = path =>
OUTSIDE_JEST_VM_PROTOCOL + '//' + encodeURIComponent(path);
exports.createOutsideJestVmPath = createOutsideJestVmPath;
const decodePossibleOutsideJestVmPath = outsideJestVmPath => {
if (outsideJestVmPath.startsWith(OUTSIDE_JEST_VM_PROTOCOL)) {
return decodeURIComponent(
outsideJestVmPath.replace(
new RegExp('^' + OUTSIDE_JEST_VM_PROTOCOL + '//'),
''
)
);
}
return undefined;
};
exports.decodePossibleOutsideJestVmPath = decodePossibleOutsideJestVmPath;
const findSiblingsWithFileExtension = (
moduleFileExtensions,
from,
moduleName
) => {
if (!path().isAbsolute(moduleName) && path().extname(moduleName) === '') {
const dirname = path().dirname(from);
const pathToModule = path().resolve(dirname, moduleName);
try {
const slashedDirname = (0, _slash().default)(dirname);
const matches = _glob()
.default.sync(`${pathToModule}.*`)
.map(match => (0, _slash().default)(match))
.map(match => {
const relativePath = path().posix.relative(slashedDirname, match);
return path().posix.dirname(match) === slashedDirname
? `./${relativePath}`
: relativePath;
})
.map(match => `\t'${match}'`)
.join('\n');
if (matches) {
const foundMessage = `\n\nHowever, Jest was able to find:\n${matches}`;
const mappedModuleFileExtensions = moduleFileExtensions
.map(ext => `'${ext}'`)
.join(', ');
return (
foundMessage +
"\n\nYou might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently " +
`[${mappedModuleFileExtensions}].\n\nSee https://jestjs.io/docs/configuration#modulefileextensions-arraystring`
);
}
} catch {}
}
return '';
};
exports.findSiblingsWithFileExtension = findSiblingsWithFileExtension;

View File

@@ -0,0 +1,142 @@
/**
* 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 { JestEnvironment } from '@jest/environment';
import type * as JestGlobals from '@jest/globals';
import type { SourceMapRegistry } from '@jest/source-map';
import type { V8CoverageResult } from '@jest/test-result';
import { CallerTransformOptions, ScriptTransformer, ShouldInstrumentOptions, shouldInstrument } from '@jest/transform';
import type { Config, Global } from '@jest/types';
import type { IModuleMap } from 'jest-haste-map';
import HasteMap from 'jest-haste-map';
import Resolver from 'jest-resolve';
import type { Context } from './types';
export type { Context } from './types';
interface JestGlobals extends Global.TestFrameworkGlobals {
expect: typeof JestGlobals.expect;
}
declare type HasteMapOptions = {
console?: Console;
maxWorkers: number;
resetCache: boolean;
watch?: boolean;
watchman: boolean;
};
interface InternalModuleOptions extends Required<CallerTransformOptions> {
isInternalModule: boolean;
}
export default class Runtime {
private readonly _cacheFS;
private readonly _config;
private readonly _coverageOptions;
private _currentlyExecutingModulePath;
private readonly _environment;
private readonly _explicitShouldMock;
private readonly _explicitShouldMockModule;
private _fakeTimersImplementation;
private readonly _internalModuleRegistry;
private _isCurrentlyExecutingManualMock;
private _mainModule;
private readonly _mockFactories;
private readonly _mockMetaDataCache;
private _mockRegistry;
private _isolatedMockRegistry;
private _moduleMockRegistry;
private readonly _moduleMockFactories;
private readonly _moduleMocker;
private _isolatedModuleRegistry;
private _moduleRegistry;
private readonly _esmoduleRegistry;
private readonly _cjsNamedExports;
private readonly _esmModuleLinkingMap;
private readonly _testPath;
private readonly _resolver;
private _shouldAutoMock;
private readonly _shouldMockModuleCache;
private readonly _shouldUnmockTransitiveDependenciesCache;
private readonly _sourceMapRegistry;
private readonly _scriptTransformer;
private readonly _fileTransforms;
private readonly _fileTransformsMutex;
private _v8CoverageInstrumenter;
private _v8CoverageResult;
private readonly _transitiveShouldMock;
private _unmockList;
private readonly _virtualMocks;
private readonly _virtualModuleMocks;
private _moduleImplementation?;
private readonly jestObjectCaches;
private jestGlobals?;
private readonly esmConditions;
private readonly cjsConditions;
private isTornDown;
constructor(config: Config.ProjectConfig, environment: JestEnvironment, resolver: Resolver, transformer: ScriptTransformer, cacheFS: Map<string, string>, coverageOptions: ShouldInstrumentOptions, testPath: Config.Path);
static shouldInstrument: typeof shouldInstrument;
static createContext(config: Config.ProjectConfig, options: {
console?: Console;
maxWorkers: number;
watch?: boolean;
watchman: boolean;
}): Promise<Context>;
static createHasteMap(config: Config.ProjectConfig, options?: HasteMapOptions): HasteMap;
static createResolver(config: Config.ProjectConfig, moduleMap: IModuleMap): Resolver;
static runCLI(): Promise<never>;
static getCLIOptions(): never;
unstable_shouldLoadAsEsm(path: Config.Path): boolean;
private loadEsmModule;
private resolveModule;
private linkAndEvaluateModule;
unstable_importModule(from: Config.Path, moduleName?: string): Promise<void>;
private loadCjsAsEsm;
private importMock;
private getExportsOfCjs;
requireModule<T = unknown>(from: Config.Path, moduleName?: string, options?: InternalModuleOptions, isRequireActual?: boolean): 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;
getSourceMaps(): SourceMapRegistry;
setMock(from: string, moduleName: string, mockFactory: () => unknown, options?: {
virtual?: boolean;
}): void;
private setModuleMock;
restoreAllMocks(): void;
resetAllMocks(): void;
clearAllMocks(): void;
teardown(): void;
private _resolveModule;
private _requireResolve;
private _requireResolvePaths;
private _execModule;
private transformFile;
private transformFileAsync;
private createScriptFromCode;
private _requireCoreModule;
private _importCoreModule;
private _getMockedNativeModule;
private _generateMock;
private _shouldMock;
private _createRequireImplementation;
private _createJestObjectFor;
private _logFormattedReferenceError;
private wrapCodeInModuleWrapper;
private constructModuleWrapperStart;
private constructInjectedModuleParameters;
private handleExecutionError;
private getGlobalsForCjs;
private getGlobalsForEsm;
private getGlobalsFromEnvironment;
private readFile;
setGlobalsForRuntime(globals: JestGlobals): void;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,15 @@
/**
* 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 { FS as HasteFS, ModuleMap } from 'jest-haste-map';
import type Resolver from 'jest-resolve';
export declare type Context = {
config: Config.ProjectConfig;
hasteFS: HasteFS;
moduleMap: ModuleMap;
resolver: Resolver;
};

View File

@@ -0,0 +1 @@
'use strict';