Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/js/node/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,25 @@ class TestContext {
}

before(arg0: unknown, arg1: unknown) {
const { fn } = createHook(arg0, arg1);
const { fn } = createHook(arg0, arg1, this);
const { beforeAll } = bunTest();
beforeAll(fn);
}

after(arg0: unknown, arg1: unknown) {
const { fn } = createHook(arg0, arg1);
const { fn } = createHook(arg0, arg1, this);
const { afterAll } = bunTest();
afterAll(fn);
}

beforeEach(arg0: unknown, arg1: unknown) {
const { fn } = createHook(arg0, arg1);
const { fn } = createHook(arg0, arg1, this);
const { beforeEach } = bunTest();
beforeEach(fn);
}

afterEach(arg0: unknown, arg1: unknown) {
const { fn } = createHook(arg0, arg1);
const { fn } = createHook(arg0, arg1, this);
const { afterEach } = bunTest();
afterEach(fn);
}
Expand Down Expand Up @@ -374,13 +374,13 @@ function parseHookOptions(arg0: unknown, arg1: unknown) {
return { fn, options };
}

function createHook(arg0: unknown, arg1: unknown) {
function createHook(arg0: unknown, arg1: unknown, context?: TestContext) {
const { fn, options } = parseHookOptions(arg0, arg1);

const runHook = (done: (error?: unknown) => void) => {
let result: unknown;
try {
result = fn();
result = context ? fn(context) : fn();
} catch (error) {
done(error);
return;
Expand All @@ -396,7 +396,7 @@ function createHook(arg0: unknown, arg1: unknown) {
}

type TestFn = (ctx: TestContext) => unknown | Promise<unknown>;
type HookFn = () => unknown | Promise<unknown>;
type HookFn = (ctx?: TestContext) => unknown | Promise<unknown>;

type TestOptions = {
concurrency?: number | boolean | null;
Expand Down