japa
Version:
Lean test runner for Node.js
109 lines (108 loc) • 3.07 kB
TypeScript
/**
* @module Core
*/
import { Test } from '../Test';
import { ICallback, IResolver, IGroupReport, ITestOptions, IOptions } from '../Contracts';
/**
* Group holds `n` number of tests to be executed. Groups also allows
* defining hooks to be called before and after each test and the
* group itself.
*/
export declare class Group<T extends any[], H extends any[]> {
title: string;
private _resolveTestFn;
private _resolveHookFn;
private _options;
private _hooks;
/**
* Timeout defined on group will be applied to
* all the tests by default.
*/
private _timeout;
/**
* The test error (if any)
*/
private _error;
/**
* Has test been executed
*/
private _completed;
/**
* An array of tests related to the group. They are mutated by the
* run method to filter and keep only the one's that matches
* the grep filter.
*/
private _tests;
/**
* Storing whether the group has any failing tests or
* not.
*/
private _hasFailingTests;
/**
* Is there a cherry picked test using the `only` property
* or not?
*/
private _hasCherryPickedTest;
constructor(title: string, _resolveTestFn: IResolver<T>, _resolveHookFn: IResolver<H>, _options: IOptions);
/**
* Returns a boolean telling if group or any of the tests inside
* the group has errors.
*/
get hasErrors(): boolean;
/**
* Filter tests if grep value is defined
*/
private _filterTests;
/**
* Run a hook and if it raises error, then we will
* set the completed flag to true, along with the
* error.
*/
private _runHook;
/**
* Runs a single test along side with it's hooks.
*/
private _runTest;
/**
* Runs all the tests one by one and also executes
* the beforeEach and afterEach hooks
*/
private _runTests;
/**
* Returns the JSON report for the group. The output of this
* method is emitted as an event.
*/
toJSON(): IGroupReport;
/**
* Define timeout for all the tests inside the group. Still
* each test can override it's own timeout.
*/
timeout(duration: number): this;
/**
* Create a new test as part of this group.
*/
test(title: string, callback: ICallback<T>, testOptions?: Partial<ITestOptions>): Test<T>;
/**
* Add before hook to be executed before the group starts
* executing tests.
*/
before(cb: ICallback<H>): this;
/**
* Add after hook to be executed after the group has executed
* all the tests.
*/
after(cb: ICallback<H>): this;
/**
* Add before each hook to be execute before each test
*/
beforeEach(cb: ICallback<H>): this;
/**
* Add after each hook to be execute before each test
*/
afterEach(cb: ICallback<H>): this;
/**
* Run the group with it's hooks and all tests. Shouldn't be called
* by the end user and Japa itself will call this method
*/
run(): Promise<void>;
}