UNPKG

3.78 kBTypeScriptView Raw
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 */
7import type { CoverageMapData } from 'istanbul-lib-coverage';
8export declare type ValidTestReturnValues = void | undefined;
9declare type TestReturnValuePromise = Promise<unknown>;
10declare type TestReturnValueGenerator = Generator<void, unknown, void>;
11export declare type TestReturnValue = ValidTestReturnValues | TestReturnValuePromise;
12export declare type TestContext = Record<string, unknown>;
13export declare type DoneFn = (reason?: string | Error) => void;
14export declare type DoneTakingTestFn = (this: TestContext | undefined, done: DoneFn) => ValidTestReturnValues;
15export declare type PromiseReturningTestFn = (this: TestContext | undefined) => TestReturnValue;
16export declare type GeneratorReturningTestFn = (this: TestContext | undefined) => TestReturnValueGenerator;
17export declare type TestName = string;
18export declare type TestFn = PromiseReturningTestFn | GeneratorReturningTestFn | DoneTakingTestFn;
19export declare type ConcurrentTestFn = () => TestReturnValuePromise;
20export declare type BlockFn = () => void;
21export declare type BlockName = string;
22export declare type HookFn = TestFn;
23export declare type Col = unknown;
24export declare type Row = Array<Col>;
25export declare type Table = Array<Row>;
26export declare type ArrayTable = Table | Row;
27export declare type TemplateTable = TemplateStringsArray;
28export declare type TemplateData = Array<unknown>;
29export declare type EachTable = ArrayTable | TemplateTable;
30export declare type TestCallback = BlockFn | TestFn | ConcurrentTestFn;
31export declare type EachTestFn<EachCallback extends TestCallback> = (...args: Array<any>) => ReturnType<EachCallback>;
32declare type Jasmine = {
33 _DEFAULT_TIMEOUT_INTERVAL?: number;
34 addMatchers: (matchers: Record<string, unknown>) => void;
35};
36declare type Each<EachCallback extends TestCallback> = ((table: EachTable, ...taggedTemplateData: Array<unknown>) => (title: string, test: EachTestFn<EachCallback>, timeout?: number) => void) | (() => () => void);
37export interface HookBase {
38 (fn: HookFn, timeout?: number): void;
39}
40export interface ItBase {
41 (testName: TestName, fn: TestFn, timeout?: number): void;
42 each: Each<TestFn>;
43}
44export interface It extends ItBase {
45 only: ItBase;
46 skip: ItBase;
47 todo: (testName: TestName) => void;
48}
49export interface ItConcurrentBase {
50 (testName: string, testFn: ConcurrentTestFn, timeout?: number): void;
51 each: Each<ConcurrentTestFn>;
52}
53export interface ItConcurrentExtended extends ItConcurrentBase {
54 only: ItConcurrentBase;
55 skip: ItConcurrentBase;
56}
57export interface ItConcurrent extends It {
58 concurrent: ItConcurrentExtended;
59}
60export interface DescribeBase {
61 (blockName: BlockName, blockFn: BlockFn): void;
62 each: Each<BlockFn>;
63}
64export interface Describe extends DescribeBase {
65 only: DescribeBase;
66 skip: DescribeBase;
67}
68export interface TestFrameworkGlobals {
69 it: ItConcurrent;
70 test: ItConcurrent;
71 fit: ItBase & {
72 concurrent?: ItConcurrentBase;
73 };
74 xit: ItBase;
75 xtest: ItBase;
76 describe: Describe;
77 xdescribe: DescribeBase;
78 fdescribe: DescribeBase;
79 beforeAll: HookBase;
80 beforeEach: HookBase;
81 afterEach: HookBase;
82 afterAll: HookBase;
83}
84export interface GlobalAdditions extends TestFrameworkGlobals {
85 __coverage__: CoverageMapData;
86 jasmine: Jasmine;
87 fail: () => void;
88 pending: () => void;
89 spyOn: () => void;
90 spyOnProperty: () => void;
91}
92export interface Global extends GlobalAdditions, Omit<typeof globalThis, keyof GlobalAdditions> {
93 [extras: string]: unknown;
94}
95export {};