@plugjs/expect5
Version:
Unit Testing for the PlugJS Build System ========================================
87 lines (86 loc) • 3.29 kB
TypeScript
/**
* A _callable_ (possibly async) function.
*
* When the timeout configured is reached, the passed `signal` will be aborted.
*/
export type Call = (this: undefined, signal: AbortSignal) => any | Promise<any>;
/** Flag types for an {@link Executable} */
export type Flag = 'skip' | 'only' | undefined;
/** An {@link Executor} notifying lifecycle events for {@link Executable}s */
export interface Executor {
start(executable: Suite | Spec | Hook): {
notify(error: Error): void;
done(skip?: boolean): void;
};
}
export declare function getCurrentSuite(): Suite;
export declare function skip(): void;
/** Our {@link Suite} implementation */
export declare class Suite {
readonly parent: Suite | undefined;
readonly name: string;
readonly call: Call;
readonly timeout: number;
flag: Flag;
private _beforeAll;
private _beforeEach;
private _afterAll;
private _afterEach;
private _suites;
private _specs;
private _children;
private _setup;
constructor(parent: Suite | undefined, name: string, call: Call, timeout?: number, flag?: Flag);
static [Symbol.hasInstance](instance: any): boolean;
get specs(): number;
/** Add a child {@link Suite} to this */
addSuite(suite: Suite): void;
/** Add a {@link Spec} to this */
addSpec(spec: Spec): void;
/** Add a _before all_ {@link Hook} to this */
addBeforeAllHook(hook: Hook): void;
/** Add a _before each_ {@link Hook} to this */
addBeforeEachHook(hook: Hook): void;
/** Add a _after all_ {@link Hook} to this */
addAfterAllHook(hook: Hook): void;
/** Add a _after each_ {@link Hook} to this */
addAfterEachHook(hook: Hook): void;
/**
* Setup this {@link Suite} invoking its main function, then initializing all
* children {@link Suite Suites}, and finally normalizing execution flags.
*/
setup(): Promise<void>;
/**
* Execute this suite, executing all {@link Hook hooks} and children
* {@link Spec specs} and {@link Suite suites}
*/
execute(executor: Executor, skip?: boolean): Promise<Error | void>;
}
/** Our {@link Spec} implementation */
export declare class Spec {
readonly parent: Suite;
readonly name: string;
readonly call: Call;
readonly timeout: number;
flag: Flag;
before: Hook[];
after: Hook[];
constructor(parent: Suite, name: string, call: Call, timeout?: number, flag?: Flag);
static [Symbol.hasInstance](instance: any): boolean;
/** Execute this spec */
execute(executor: Executor, skip?: boolean): Promise<void>;
}
/** Our {@link Hook} implementation */
export declare class Hook {
readonly parent: Suite | Spec;
readonly name: 'beforeAll' | 'afterAll' | 'beforeEach' | 'afterEach';
readonly call: Call;
readonly timeout: number;
readonly flag: Exclude<Flag, 'only'>;
constructor(parent: Suite | Spec, name: 'beforeAll' | 'afterAll' | 'beforeEach' | 'afterEach', call: Call, timeout?: number, flag?: Exclude<Flag, 'only'>);
static [Symbol.hasInstance](instance: any): boolean;
/** Execute this hook */
execute(executor: Executor): Promise<boolean>;
/** Clone this associating it with a new {@link Suite} or {@link Spec} */
clone(parent: Suite | Spec): Hook;
}