[bun:test] preload now supports beforeAll, beforeEach, afterAll, afterEach hooks

Towards #198
This commit is contained in:
Jarred Sumner
2023-05-20 23:22:12 -07:00
parent 76e92abc7e
commit b16ddd95d9
5 changed files with 227 additions and 102 deletions

View File

@@ -654,12 +654,12 @@ pub const TestCommand = struct {
if (files.len > 1) {
for (files[0 .. files.len - 1]) |file_name| {
TestCommand.run(reporter, vm, file_name.slice(), allocator) catch {};
TestCommand.run(reporter, vm, file_name.slice(), allocator, false) catch {};
Global.mimalloc_cleanup(false);
}
}
TestCommand.run(reporter, vm, files[files.len - 1].slice(), allocator) catch {};
TestCommand.run(reporter, vm, files[files.len - 1].slice(), allocator, true) catch {};
}
};
@@ -678,6 +678,7 @@ pub const TestCommand = struct {
vm: *JSC.VirtualMachine,
file_name: string,
_: std.mem.Allocator,
is_last: bool,
) !void {
defer {
js_ast.Expr.Data.Store.reset();
@@ -769,5 +770,13 @@ pub const TestCommand = struct {
Output.flush();
}
}
if (is_last) {
if (jest.Jest.runner != null) {
if (jest.DescribeScope.runGlobalCallbacks(vm.global, .afterAll)) |after| {
vm.global.bunVM().runErrorHandler(after, null);
}
}
}
}
};