first commit

This commit is contained in:
2026-09-08 20:28:54 +08:00
commit 2ada8d3d5a
37380 changed files with 4886169 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
/**
* 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.
*/
export default class ExpectationFailed extends Error {
}
+10
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 { DiffOptions } from 'jest-matcher-utils';
import { AssertionErrorWithStack } from './types';
declare function assertionErrorMessage(error: AssertionErrorWithStack, options: DiffOptions): string;
export default assertionErrorMessage;
+9
View File
@@ -0,0 +1,9 @@
/**
* 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 { JestEnvironment } from '@jest/environment';
declare const _default: (environment: JestEnvironment) => void;
export default _default;
+8
View File
@@ -0,0 +1,8 @@
/**
* 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 { Global } from '@jest/types';
export declare function installErrorOnPrivate(global: Global.Global): void;
+16
View File
@@ -0,0 +1,16 @@
/**
* 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 { FailedAssertion } from '@jest/test-result';
export declare type Options = {
matcherName: string;
passed: boolean;
actual?: any;
error?: any;
expected?: any;
message?: string | null;
};
export default function expectationResultFactory(options: Options, initError?: Error): FailedAssertion;
+16
View File
@@ -0,0 +1,16 @@
/**
* 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 { Config } from '@jest/types';
import { TestResult } from '@jest/test-result';
import { JestEnvironment } from '@jest/environment';
import { RuntimeType as Runtime } from 'jest-runtime';
import { Jasmine as JestJasmine } from './types';
declare function jasmine2(globalConfig: Config.GlobalConfig, config: Config.ProjectConfig, environment: JestEnvironment, runtime: Runtime, testPath: string): Promise<TestResult>;
declare namespace jasmine2 {
type Jasmine = JestJasmine;
}
export = jasmine2;
+10
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.
*/
export default function isError(potentialError: any): {
isError: boolean;
message: string | null;
};
+25
View File
@@ -0,0 +1,25 @@
/**
* 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.
*
*/
export declare type Context = {
object: unknown;
args: Array<unknown>;
returnValue?: unknown;
};
declare class CallTracker {
track: (context: Context) => void;
any: () => boolean;
count: () => number;
argsFor: (index: number) => Array<unknown>;
all: () => Array<Context>;
allArgs: () => Array<unknown>;
first: () => Context;
mostRecent: () => Context;
reset: () => void;
constructor();
}
export default CallTracker;
+42
View File
@@ -0,0 +1,42 @@
/**
* 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 { AssertionErrorWithStack, Jasmine, Reporter, Spy } from '../types';
import { default as Spec } from './Spec';
import Suite from './Suite';
export default function (j$: Jasmine): {
new (_options?: object | undefined): {
specFilter: (spec: Spec) => boolean;
catchExceptions: (value: unknown) => boolean;
throwOnExpectationFailure: (value: unknown) => void;
catchingExceptions: () => boolean;
topSuite: () => Suite;
fail: (error: Error | AssertionErrorWithStack) => void;
pending: (message: string) => void;
afterAll: (afterAllFunction: (done: (error?: any) => void) => void, timeout?: number | undefined) => void;
fit: (description: string, fn: (done: (error?: any) => void) => void, timeout?: number | undefined) => Spec;
throwingExpectationFailures: () => boolean;
randomizeTests: (value: unknown) => void;
randomTests: () => boolean;
seed: (value: unknown) => unknown;
execute: (runnablesToRun?: string[] | undefined, suiteTree?: Suite | undefined) => Promise<void>;
fdescribe: (description: string, specDefinitions: Function) => Suite;
spyOn: (obj: Record<string, Spy>, methodName: string, accessType?: "get" | "set" | "writable" | "configurable" | "enumerable" | "value" | undefined) => Spy;
beforeEach: (beforeEachFunction: (done: (error?: any) => void) => void, timeout?: number | undefined) => void;
afterEach: (afterEachFunction: (done: (error?: any) => void) => void, timeout?: number | undefined) => void;
clearReporters: () => void;
addReporter: (reporterToAdd: Reporter) => void;
it: (description: string, fn: (done: (error?: any) => void) => void, timeout?: number | undefined) => Spec;
xdescribe: (description: string, specDefinitions: Function) => Suite;
xit: (description: string, fn: (done: (error?: any) => void) => void, timeout?: number | undefined) => Spec;
beforeAll: (beforeAllFunction: (done: (error?: any) => void) => void, timeout?: number | undefined) => void;
todo: () => Spec;
provideFallbackReporter: (reporterToAdd: Reporter) => void;
allowRespy: (allow: boolean) => void;
describe: (description: string, specDefinitions: Function) => Suite;
};
};
+31
View File
@@ -0,0 +1,31 @@
/**
* 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 { Reporter, RunDetails } from '../types';
import { SpecResult } from './Spec';
import { SuiteResult } from './Suite';
import Timer from './Timer';
export default class JsApiReporter implements Reporter {
started: boolean;
finished: boolean;
runDetails: RunDetails;
jasmineStarted: (runDetails: RunDetails) => void;
jasmineDone: (runDetails: RunDetails) => void;
status: () => unknown;
executionTime: () => unknown;
suiteStarted: (result: SuiteResult) => void;
suiteDone: (result: SuiteResult) => void;
suiteResults: (index: number, length: number) => Array<SuiteResult>;
suites: () => Record<string, SuiteResult>;
specResults: (index: number, length: number) => Array<SpecResult>;
specDone: (result: SpecResult) => void;
specs: () => Array<SpecResult>;
specStarted: (spec: SpecResult) => void;
constructor(options: {
timer?: Timer;
});
}
+22
View File
@@ -0,0 +1,22 @@
/**
* 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 { Reporter, RunDetails } from '../types';
import { SpecResult } from './Spec';
import { SuiteResult } from './Suite';
export default class ReportDispatcher implements Reporter {
addReporter: (reporter: Reporter) => void;
provideFallbackReporter: (reporter: Reporter) => void;
clearReporters: () => void;
jasmineDone: (runDetails: RunDetails) => void;
jasmineStarted: (runDetails: RunDetails) => void;
specDone: (result: SpecResult) => void;
specStarted: (spec: SpecResult) => void;
suiteDone: (result: SuiteResult) => void;
suiteStarted: (result: SuiteResult) => void;
constructor(methods: Array<keyof Reporter>);
}
+81
View File
@@ -0,0 +1,81 @@
/**
* 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 { Config } from '@jest/types';
import { FailedAssertion, Milliseconds, Status } from '@jest/test-result';
import ExpectationFailed from '../ExpectationFailed';
import expectationResultFactory, { Options as ExpectationResultFactoryOptions } from '../expectationResultFactory';
import { QueueableFn, default as queueRunner } from '../queueRunner';
import { AssertionErrorWithStack } from '../types';
export declare type Attributes = {
id: string;
resultCallback: (result: Spec['result']) => void;
description: string;
throwOnExpectationFailure: unknown;
getTestPath: () => Config.Path;
queueableFn: QueueableFn;
beforeAndAfterFns: () => {
befores: Array<QueueableFn>;
afters: Array<QueueableFn>;
};
userContext: () => unknown;
onStart: (context: Spec) => void;
getSpecName: (spec: Spec) => string;
queueRunnerFactory: typeof queueRunner;
};
export declare type SpecResult = {
id: string;
description: string;
fullName: string;
duration?: Milliseconds;
failedExpectations: Array<FailedAssertion>;
testPath: Config.Path;
passedExpectations: Array<ReturnType<typeof expectationResultFactory>>;
pendingReason: string;
status: Status;
__callsite?: {
getColumnNumber: () => number;
getLineNumber: () => number;
};
};
export default class Spec {
id: string;
description: string;
resultCallback: (result: SpecResult) => void;
queueableFn: QueueableFn;
beforeAndAfterFns: () => {
befores: Array<QueueableFn>;
afters: Array<QueueableFn>;
};
userContext: () => unknown;
onStart: (spec: Spec) => void;
getSpecName: (spec: Spec) => string;
queueRunnerFactory: typeof queueRunner;
throwOnExpectationFailure: boolean;
initError: Error;
result: SpecResult;
disabled?: boolean;
currentRun?: ReturnType<typeof queueRunner>;
markedTodo?: boolean;
markedPending?: boolean;
expand?: boolean;
static pendingSpecExceptionMessage: string;
static isPendingSpecException(e: Error): boolean;
constructor(attrs: Attributes);
addExpectationResult(passed: boolean, data: ExpectationResultFactoryOptions, isError?: boolean): void;
execute(onComplete: Function, enabled: boolean): void;
cancel(): void;
onException(error: ExpectationFailed | AssertionErrorWithStack): void;
disable(): void;
pend(message?: string): void;
todo(): void;
getResult(): SpecResult;
status(enabled?: boolean): "todo" | "passed" | "failed" | "pending" | "disabled";
isExecutable(): boolean;
getFullName(): string;
isAssertionError(error: Error): boolean;
}
+22
View File
@@ -0,0 +1,22 @@
/**
* 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.
*
*/
export default class SpyStrategy {
identity: () => string;
exec: (...args: Array<any>) => unknown;
callThrough: () => unknown;
returnValue: (value: unknown) => unknown;
returnValues: () => unknown;
throwError: (something: string | Error) => unknown;
callFake: (fn: Function) => unknown;
stub: (fn: Function) => unknown;
constructor({ name, fn, getSpy, }?: {
name?: string;
fn?: Function;
getSpy?: () => unknown;
});
}
+61
View File
@@ -0,0 +1,61 @@
/**
* 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 { Config } from '@jest/types';
import expectationResultFactory from '../expectationResultFactory';
import { QueueableFn } from '../queueRunner';
import Spec from './Spec';
export declare type SuiteResult = {
id: string;
description: string;
fullName: string;
failedExpectations: Array<ReturnType<typeof expectationResultFactory>>;
testPath: Config.Path;
status?: string;
};
export declare type Attributes = {
id: string;
parentSuite?: Suite;
description: string;
throwOnExpectationFailure?: boolean;
getTestPath: () => Config.Path;
};
export default class Suite {
id: string;
parentSuite?: Suite;
description: string;
throwOnExpectationFailure: boolean;
beforeFns: Array<QueueableFn>;
afterFns: Array<QueueableFn>;
beforeAllFns: Array<QueueableFn>;
afterAllFns: Array<QueueableFn>;
disabled: boolean;
children: Array<Suite | Spec>;
result: SuiteResult;
sharedContext?: object;
markedPending: boolean;
markedTodo: boolean;
isFocused: boolean;
constructor(attrs: Attributes);
getFullName(): string;
disable(): void;
pend(_message?: string): void;
beforeEach(fn: QueueableFn): void;
beforeAll(fn: QueueableFn): void;
afterEach(fn: QueueableFn): void;
afterAll(fn: QueueableFn): void;
addChild(child: Suite | Spec): void;
status(): "failed" | "pending" | "disabled" | "finished";
isExecutable(): boolean;
canBeReentered(): boolean;
getResult(): SuiteResult;
sharedUserContext(): object;
clonedSharedUserContext(): object;
onException(...args: Parameters<Spec['onException']>): void;
addExpectationResult(...args: Parameters<Spec['addExpectationResult']>): void;
execute(..._args: Array<any>): void;
}
+14
View File
@@ -0,0 +1,14 @@
/**
* 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.
*
*/
export default class Timer {
start: () => void;
elapsed: () => number;
constructor(options?: {
now?: () => number;
});
}
+13
View File
@@ -0,0 +1,13 @@
/**
* 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 { Spy } from '../types';
interface Fn extends Record<string, any> {
(): any;
}
declare function createSpy(name: string, originalFn: Fn): Spy;
export default createSpy;
+27
View File
@@ -0,0 +1,27 @@
/**
* 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 { Jasmine } from '../types';
import JsApiReporter from './JsApiReporter';
export declare const create: (createOptions: Record<string, any>) => Jasmine;
export declare const _interface: (jasmine: Jasmine, env: any) => {
describe(description: string, specDefinitions: Function): any;
xdescribe(description: string, specDefinitions: Function): any;
fdescribe(description: string, specDefinitions: Function): any;
it(): any;
xit(): any;
fit(): any;
beforeEach(): any;
afterEach(): any;
beforeAll(): any;
afterAll(): any;
pending(): any;
fail(): any;
spyOn(obj: Record<string, any>, methodName: string, accessType?: string | undefined): any;
jsApiReporter: JsApiReporter;
jasmine: Jasmine;
};
+18
View File
@@ -0,0 +1,18 @@
/**
* 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 { Spy } from '../types';
export default class SpyRegistry {
allowRespy: (allow: unknown) => void;
spyOn: (obj: Record<string, Spy>, methodName: string, accessType?: keyof PropertyDescriptor) => Spy;
clearSpies: () => void;
respy: unknown;
private _spyOnProperty;
constructor({ currentSpies, }?: {
currentSpies?: () => Array<Spy>;
});
}
+12
View File
@@ -0,0 +1,12 @@
/**
* 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.
*/
/**
* This module adds ability to test async promise code with jasmine by
* returning a promise from `it/test` and `before/afterEach/All` blocks.
*/
import { Config, Global } from '@jest/types';
export default function jasmineAsyncInstall(globalConfig: Config.GlobalConfig, global: Global.Global): void;
+10
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.
*/
declare const _default: (config: {
expand: boolean;
}) => void;
export default _default;
+7
View File
@@ -0,0 +1,7 @@
/**
* 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.
*/
export default function pTimeout(promise: Promise<any>, ms: number, clearTimeout: NodeJS.Global['clearTimeout'], setTimeout: NodeJS.Global['setTimeout'], onTimeout: () => any): Promise<any>;
+26
View File
@@ -0,0 +1,26 @@
/**
* 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.
*/
declare type Global = NodeJS.Global;
export declare type Options = {
clearTimeout: Global['clearTimeout'];
fail: (error: Error) => void;
onException: (error: Error) => void;
queueableFns: Array<QueueableFn>;
setTimeout: Global['setTimeout'];
userContext: any;
};
export declare type QueueableFn = {
fn: (done: (error?: any) => void) => void;
timeout?: () => number;
initError?: Error;
};
export default function queueRunner(options: Options): {
cancel: any;
catch: <TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined) => Promise<void | TResult>;
then: <TResult1 = void, TResult2 = never>(onfulfilled?: ((value: void) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => Promise<TResult1 | TResult2>;
};
export {};
+31
View File
@@ -0,0 +1,31 @@
/**
* 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 { Config } from '@jest/types';
import { TestResult } from '@jest/test-result';
import { SpecResult } from './jasmine/Spec';
import { SuiteResult } from './jasmine/Suite';
import { Reporter, RunDetails } from './types';
export default class Jasmine2Reporter implements Reporter {
private _testResults;
private _globalConfig;
private _config;
private _currentSuites;
private _resolve;
private _resultsPromise;
private _startTimes;
private _testPath;
constructor(globalConfig: Config.GlobalConfig, config: Config.ProjectConfig, testPath: Config.Path);
jasmineStarted(_runDetails: RunDetails): void;
specStarted(spec: SpecResult): void;
specDone(result: SpecResult): void;
suiteStarted(suite: SuiteResult): void;
suiteDone(_result: SuiteResult): void;
jasmineDone(_runDetails: RunDetails): void;
getResults(): Promise<TestResult>;
private _addMissingMessageToStack;
private _extractSpecResults;
}
+16
View File
@@ -0,0 +1,16 @@
/**
* 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 { Config } from '@jest/types';
import { Plugin } from 'pretty-format';
export declare type SetupOptions = {
config: Config.ProjectConfig;
globalConfig: Config.GlobalConfig;
localRequire: (moduleName: string) => Plugin;
testPath: Config.Path;
};
declare const _default: ({ config, globalConfig, localRequire, testPath, }: SetupOptions) => import("jest-snapshot/build/State").default;
export default _default;
+26
View File
@@ -0,0 +1,26 @@
/**
* 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 Suite from './jasmine/Suite';
declare type Options = {
nodeComplete: (suite: TreeNode) => void;
nodeStart: (suite: TreeNode) => void;
queueRunnerFactory: any;
runnableIds: Array<string>;
tree: TreeNode;
};
export declare type TreeNode = {
afterAllFns: Array<any>;
beforeAllFns: Array<any>;
disabled?: boolean;
execute: (onComplete: () => void, enabled: boolean) => void;
id: string;
onException: (error: Error) => void;
sharedUserContext: () => any;
children?: Array<TreeNode>;
} & Pick<Suite, 'getResult' | 'parentSuite' | 'result' | 'markedPending'>;
export default function treeProcessor(options: Options): void;
export {};
+73
View File
@@ -0,0 +1,73 @@
/// <reference types="node" />
/**
* 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.
*/
/// <reference types="node" />
import { AssertionError } from 'assert';
import { Config } from '@jest/types';
import expect = require('expect');
import { default as Spec, SpecResult } from './jasmine/Spec';
import JsApiReporter from './jasmine/JsApiReporter';
import Timer from './jasmine/Timer';
import Env from './jasmine/Env';
import createSpy from './jasmine/createSpy';
import ReportDispatcher from './jasmine/ReportDispatcher';
import SpyRegistry from './jasmine/spyRegistry';
import { default as Suite, SuiteResult } from './jasmine/Suite';
import SpyStrategy from './jasmine/SpyStrategy';
import CallTracker from './jasmine/CallTracker';
export interface AssertionErrorWithStack extends AssertionError {
stack: string;
}
export declare type SyncExpectationResult = {
pass: boolean;
message: () => string;
};
export declare type AsyncExpectationResult = Promise<SyncExpectationResult>;
export declare type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
export declare type RawMatcherFn = (expected: any, actual: any, options?: any) => ExpectationResult;
export declare type RunDetails = {
totalSpecsDefined?: number;
failedExpectations?: SuiteResult['failedExpectations'];
};
export declare type Reporter = {
jasmineDone: (runDetails: RunDetails) => void;
jasmineStarted: (runDetails: RunDetails) => void;
specDone: (result: SpecResult) => void;
specStarted: (spec: SpecResult) => void;
suiteDone: (result: SuiteResult) => void;
suiteStarted: (result: SuiteResult) => void;
};
export interface Spy extends Record<string, any> {
(this: Record<string, unknown>, ...args: Array<any>): unknown;
and: SpyStrategy;
calls: CallTracker;
restoreObjectToOriginalState?: () => void;
}
export declare type Jasmine = {
_DEFAULT_TIMEOUT_INTERVAL: number;
DEFAULT_TIMEOUT_INTERVAL: number;
currentEnv_: ReturnType<typeof Env>['prototype'];
getEnv: (options?: object) => ReturnType<typeof Env>['prototype'];
createSpy: typeof createSpy;
Env: ReturnType<typeof Env>;
JsApiReporter: typeof JsApiReporter;
ReportDispatcher: typeof ReportDispatcher;
Spec: typeof Spec;
SpyRegistry: typeof SpyRegistry;
Suite: typeof Suite;
Timer: typeof Timer;
version: string;
testPath: Config.Path;
addMatchers: Function;
} & typeof expect & NodeJS.Global;
declare global {
module NodeJS {
interface Global {
expect: typeof expect;
}
}
}