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
+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>;
});
}