diff options
author | 2022-02-05 21:26:31 -0800 | |
---|---|---|
committer | 2022-02-05 21:26:31 -0800 | |
commit | e431dbe5bdba4624dbf3f87480fd61d5a5ddfba7 (patch) | |
tree | d9483968d623c0604ae2f458693527e22be25bbe | |
parent | 3063df9b788f477df07057f26fbb34ec3b119ec5 (diff) | |
download | bun-e431dbe5bdba4624dbf3f87480fd61d5a5ddfba7.tar.gz bun-e431dbe5bdba4624dbf3f87480fd61d5a5ddfba7.tar.zst bun-e431dbe5bdba4624dbf3f87480fd61d5a5ddfba7.zip |
Handle promise rejections in tests
-rw-r--r-- | src/cli/test_command.zig | 21 | ||||
-rw-r--r-- | src/javascript/jsc/test/jest.zig | 33 |
2 files changed, 35 insertions, 19 deletions
diff --git a/src/cli/test_command.zig b/src/cli/test_command.zig index c8949ba9b..5a479189f 100644 --- a/src/cli/test_command.zig +++ b/src/cli/test_command.zig @@ -122,6 +122,7 @@ const Scanner = struct { pub fn scan(this: *Scanner, path_literal: string) void { var parts = &[_]string{ this.fs.top_level_dir, path_literal }; const path = this.fs.absBuf(parts, &this.scan_dir_buf); + var root = this.readDirWithName(path, null) catch |err| { if (err == error.NotDir) { if (this.isTestFile(path)) { @@ -274,9 +275,10 @@ pub const TestCommand = struct { scanner.dirs_to_scan.deinit(); const test_files = scanner.results.toOwnedSlice(); - - // vm.bundler.fs.fs.readDirectory(_dir: string, _handle: ?std.fs.Dir) - runAllTests(reporter, vm, test_files, ctx.allocator); + if (test_files.len > 0) { + // vm.bundler.fs.fs.readDirectory(_dir: string, _handle: ?std.fs.Dir) + runAllTests(reporter, vm, test_files, ctx.allocator); + } Output.pretty("\n", .{}); Output.flush(); @@ -385,12 +387,13 @@ pub const TestCommand = struct { vm.tick(); } - var result = promise.result(vm.global.vm()); - if (result.isError() or - result.isAggregateError(vm.global) or - result.isException(vm.global.vm())) - { - vm.defaultErrorHandler(result, null); + switch (promise.status(vm.global.vm())) { + .Rejected => { + var result = promise.result(vm.global.vm()); + vm.defaultErrorHandler(result, null); + return; + }, + else => {}, } reporter.updateDots(); diff --git a/src/javascript/jsc/test/jest.zig b/src/javascript/jsc/test/jest.zig index ea7d092b4..1d933cafe 100644 --- a/src/javascript/jsc/test/jest.zig +++ b/src/javascript/jsc/test/jest.zig @@ -613,21 +613,25 @@ pub const TestScope = struct { ) Result { var vm = VirtualMachine.vm; - var promise = JSC.JSPromise.resolvedPromise( + var promise = JSC.JSInternalPromise.resolvedPromise( vm.global, js.JSObjectCallAsFunctionReturnValue(vm.global.ref(), this.callback, null, 0, null), ); - js.JSValueUnprotect(vm.global.ref(), this.callback); + defer js.JSValueUnprotect(vm.global.ref(), this.callback); this.callback = null; while (promise.status(vm.global.vm()) == JSC.JSPromise.Status.Pending) { vm.tick(); } - var result = promise.result(vm.global.vm()); - - if (result.isException(vm.global.vm()) or result.isError() or result.isAggregateError(vm.global)) { - vm.defaultErrorHandler(result, null); - return .{ .fail = this.counter.actual }; + switch (promise.status(vm.global.vm())) { + .Rejected => { + vm.defaultErrorHandler(promise.result(vm.global.vm()), null); + return .{ .fail = this.counter.actual }; + }, + else => { + // don't care about the result + _ = promise.result(vm.global.vm()); + }, } if (this.counter.expected > 0 and this.counter.expected < this.counter.actual) { @@ -737,9 +741,18 @@ pub const DescribeScope = struct { { var result = js.JSObjectCallAsFunctionReturnValue(ctx, callback, thisObject, 0, null); - if (result.isException(ctx.ptr().vm())) { - exception.* = result.asObjectRef(); - return null; + var vm = JSC.VirtualMachine.vm; + const promise = JSInternalPromise.resolvedPromise(ctx.ptr(), result); + while (promise.status(ctx.ptr().vm()) == JSPromise.Status.Pending) { + vm.tick(); + } + + switch (promise.status(ctx.ptr().vm())) { + JSPromise.Status.Fulfilled => {}, + else => { + exception.* = promise.result(ctx.ptr().vm()).asObjectRef(); + return null; + }, } } this.runTests(ctx); |