Add beforeAll and afterAll hooks.
This commit is contained in:
parent
2e844596bd
commit
d8f64e1de6
|
@ -17,8 +17,19 @@ export class Group {
|
|||
public results: Result[] = [];
|
||||
public tests: Test[] = [];
|
||||
|
||||
private _afterAll: (() => Promise<void>) | undefined;
|
||||
private _beforeAll: (() => Promise<void>) | undefined;
|
||||
|
||||
constructor(public name: string) {}
|
||||
|
||||
afterAll(fn: Group["_afterAll"]): void {
|
||||
this._afterAll = fn;
|
||||
}
|
||||
|
||||
beforeAll(fn: Group["_beforeAll"]): void {
|
||||
this._beforeAll = fn;
|
||||
}
|
||||
|
||||
/** Create a new test case that doesn't get run. */
|
||||
skip(name: Test["name"], fn: Test["fn"]): void {
|
||||
this.tests.push(new Test(name, fn, {skip: true}));
|
||||
|
@ -31,10 +42,18 @@ export class Group {
|
|||
|
||||
/** Run all the tests from this group and display their results. */
|
||||
async run(): Promise<void> {
|
||||
if (this._beforeAll !== undefined) {
|
||||
await this._beforeAll();
|
||||
}
|
||||
|
||||
const results = await Promise.all(
|
||||
this.tests.map(async (test) => test.run(this.context)),
|
||||
);
|
||||
|
||||
if (this._afterAll !== undefined) {
|
||||
await this._afterAll();
|
||||
}
|
||||
|
||||
console.log(
|
||||
`# %c${this.name}`,
|
||||
"font-weight: bold; text-decoration: underline;",
|
||||
|
|
Loading…
Reference in New Issue