All files / shared / global-hooks.ts

100.00% Branches 0/0
100.00% Functions 2/2
100.00% Lines 11/11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
x4
 
 
 
 
 
 
 
x4
 
 
x4
x4
x3
x4
x4
x2
x2
x4
 
x4




















import type Assert from './assert.ts';
import ModuleContext from './module-context.ts';
import type { HookFn } from '../types.ts';

/**
 * Hooks for every test in the run, in every module: `QUnit.hooks` for Node.js and Deno.
 * A global `beforeEach` runs before any module's, and a global `afterEach` after all of
 * them. Each receives `(assert, { context })`, with the test's context as `this`.
 */
const hooks: {
  beforeEach(fn: HookFn<Assert>): void;
  afterEach(fn: HookFn<Assert>): void;
} = {
  beforeEach(fn) {
    ModuleContext.globalHooks.beforeEach.push(fn);
  },
  afterEach(fn) {
    ModuleContext.globalHooks.afterEach.push(fn);
  },
};

export default hooks;