From c434b2c191cc46de04728aead0f34abd3ff63bb9 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 25 Nov 2024 18:08:42 -0800 Subject: [PATCH] zig: make throwPretty use JSError (#15410) --- src/bun.js/api/JSBundler.zig | 6 +- src/bun.js/api/server.zig | 5 +- src/bun.js/bindings/bindings.zig | 27 +- src/bun.js/test/expect.zig | 569 +++++++++++-------------------- src/bun.js/test/jest.zig | 49 +-- src/shell/interpreter.zig | 6 +- src/shell/shell.zig | 9 +- 7 files changed, 224 insertions(+), 447 deletions(-) diff --git a/src/bun.js/api/JSBundler.zig b/src/bun.js/api/JSBundler.zig index 9a7a276d76..fa535763df 100644 --- a/src/bun.js/api/JSBundler.zig +++ b/src/bun.js/api/JSBundler.zig @@ -322,15 +322,13 @@ pub const JSBundler = struct { defer path.deinit(); var dir = std.fs.cwd().openDir(path.slice(), .{}) catch |err| { - globalThis.throwPretty("{s}: failed to open root directory: {s}", .{ @errorName(err), path.slice() }); - return error.JSError; + return globalThis.throwPretty("{s}: failed to open root directory: {s}", .{ @errorName(err), path.slice() }); }; defer dir.close(); var rootdir_buf: bun.PathBuffer = undefined; const rootdir = bun.getFdPath(bun.toFD(dir.fd), &rootdir_buf) catch |err| { - globalThis.throwPretty("{s}: failed to get full root directory path: {s}", .{ @errorName(err), path.slice() }); - return error.JSError; + return globalThis.throwPretty("{s}: failed to get full root directory path: {s}", .{ @errorName(err), path.slice() }); }; try this.rootdir.appendSliceExact(rootdir); } diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 4648fafbc9..0ee0befe78 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -5330,7 +5330,7 @@ pub const ServerWebSocket = struct { callframe: *JSC.CallFrame, comptime name: string, comptime opcode: uws.Opcode, - ) JSValue { + ) bun.JSError!JSValue { const args = callframe.arguments_old(2); if (this.isClosed()) { @@ -5377,8 +5377,7 @@ pub const ServerWebSocket = struct { }, } } else { - globalThis.throwPretty("{s} requires a string or BufferSource", .{name}); - return .zero; + return globalThis.throwPretty("{s} requires a string or BufferSource", .{name}); } } } diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index cfeaee4b89..f488508018 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -3303,37 +3303,24 @@ pub const JSGlobalObject = opaque { return err; } - pub fn throw( - this: *JSGlobalObject, - comptime fmt: [:0]const u8, - args: anytype, - ) void { + pub fn throw(this: *JSGlobalObject, comptime fmt: [:0]const u8, args: anytype) void { const instance = this.createErrorInstance(fmt, args); - if (instance != .zero) - this.vm().throwError(this, instance); + bun.assert(instance != .zero); + this.vm().throwError(this, instance); } - pub fn throw2( - this: *JSGlobalObject, - comptime fmt: [:0]const u8, - args: anytype, - ) JSError { + pub fn throw2(this: *JSGlobalObject, comptime fmt: [:0]const u8, args: anytype) JSError { const instance = this.createErrorInstance(fmt, args); bun.assert(instance != .zero); return this.vm().throwError2(this, instance); } - pub fn throwPretty( - this: *JSGlobalObject, - comptime fmt: [:0]const u8, - args: anytype, - ) void { + pub fn throwPretty(this: *JSGlobalObject, comptime fmt: [:0]const u8, args: anytype) bun.JSError { const instance = switch (Output.enable_ansi_colors) { inline else => |enabled| this.createErrorInstance(Output.prettyFmt(fmt, enabled), args), }; - - if (instance != .zero) - this.vm().throwError(this, instance); + bun.assert(instance != .zero); + return this.vm().throwError2(this, instance); } extern fn JSC__JSGlobalObject__queueMicrotaskCallback(*JSGlobalObject, *anyopaque, Function: *const (fn (*anyopaque) callconv(.C) void)) void; pub fn queueMicrotaskCallback( diff --git a/src/bun.js/test/expect.zig b/src/bun.js/test/expect.zig index 34fc02a4b5..6437dcfb4d 100644 --- a/src/bun.js/test/expect.zig +++ b/src/bun.js/test/expect.zig @@ -137,7 +137,7 @@ pub const Expect = struct { return received ++ matcher_name ++ "(" ++ args ++ ")"; } - pub fn throwPrettyMatcherError(globalThis: *JSGlobalObject, custom_label: bun.String, matcher_name: anytype, matcher_params: anytype, flags: Flags, comptime message_fmt: string, message_args: anytype) void { + pub fn throwPrettyMatcherError(globalThis: *JSGlobalObject, custom_label: bun.String, matcher_name: anytype, matcher_params: anytype, flags: Flags, comptime message_fmt: string, message_args: anytype) bun.JSError { switch (Output.enable_ansi_colors) { inline else => |colors| { const chain = switch (flags.promise) { @@ -149,16 +149,10 @@ pub const Expect = struct { inline else => |use_default_label| { if (use_default_label) { const fmt = comptime Output.prettyFmt("expect(received).{s}{s}({s})\n\n" ++ message_fmt, colors); - globalThis.throwPretty(fmt, .{ - chain, - matcher_name, - matcher_params, - } ++ message_args); + return globalThis.throwPretty(fmt, .{ chain, matcher_name, matcher_params } ++ message_args); } else { const fmt = comptime Output.prettyFmt("{}\n\n" ++ message_fmt, colors); - globalThis.throwPretty(fmt, .{ - custom_label, - } ++ message_args); + return globalThis.throwPretty(fmt, .{custom_label} ++ message_args); } }, } @@ -227,7 +221,7 @@ pub const Expect = struct { if (!silent) { var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; const message = "Expected promise that rejects\nReceived promise that resolved: {any}\n"; - throwPrettyMatcherError(globalThis, custom_label, matcher_name, matcher_params, flags, message, .{value.toFmt(&formatter)}); + return throwPrettyMatcherError(globalThis, custom_label, matcher_name, matcher_params, flags, message, .{value.toFmt(&formatter)}); } return error.JSError; }, @@ -239,7 +233,7 @@ pub const Expect = struct { if (!silent) { var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; const message = "Expected promise that resolves\nReceived promise that rejected: {any}\n"; - throwPrettyMatcherError(globalThis, custom_label, matcher_name, matcher_params, flags, message, .{value.toFmt(&formatter)}); + return throwPrettyMatcherError(globalThis, custom_label, matcher_name, matcher_params, flags, message, .{value.toFmt(&formatter)}); } return error.JSError; }, @@ -254,7 +248,7 @@ pub const Expect = struct { if (!silent) { var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; const message = "Expected promise\nReceived: {any}\n"; - throwPrettyMatcherError(globalThis, custom_label, matcher_name, matcher_params, flags, message, .{value.toFmt(&formatter)}); + return throwPrettyMatcherError(globalThis, custom_label, matcher_name, matcher_params, flags, message, .{value.toFmt(&formatter)}); } return error.JSError; } @@ -402,11 +396,11 @@ pub const Expect = struct { return expect_js_value; } - pub fn throw(this: *Expect, globalThis: *JSGlobalObject, comptime signature: [:0]const u8, comptime fmt: [:0]const u8, args: anytype) void { + pub fn throw(this: *Expect, globalThis: *JSGlobalObject, comptime signature: [:0]const u8, comptime fmt: [:0]const u8, args: anytype) bun.JSError { if (this.custom_label.isEmpty()) { - globalThis.throwPretty(signature ++ fmt, args); + return globalThis.throwPretty(signature ++ fmt, args); } else { - globalThis.throwPretty("{}" ++ fmt, .{this.custom_label} ++ args); + return globalThis.throwPretty("{}" ++ fmt, .{this.custom_label} ++ args); } } @@ -454,8 +448,7 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("pass", "", true); - this.throw(globalThis, signature, "\n\n{s}\n", .{msg.slice()}); - return .zero; + return this.throw(globalThis, signature, "\n\n{s}\n", .{msg.slice()}); } // should never reach here @@ -500,8 +493,7 @@ pub const Expect = struct { defer msg.deinit(); const signature = comptime getSignature("fail", "", true); - this.throw(globalThis, signature, "\n\n{s}\n", .{msg.slice()}); - return .zero; + return this.throw(globalThis, signature, "\n\n{s}\n", .{msg.slice()}); } /// Object.is() @@ -537,8 +529,7 @@ pub const Expect = struct { inline else => |has_custom_label| { if (not) { const signature = comptime getSignature("toBe", "expected", true); - this.throw(globalThis, signature, "\n\nExpected: not {any}\n", .{right.toFmt(&formatter)}); - return .zero; + return this.throw(globalThis, signature, "\n\nExpected: not {any}\n", .{right.toFmt(&formatter)}); } const signature = comptime getSignature("toBe", "expected", false); @@ -547,8 +538,7 @@ pub const Expect = struct { (if (!has_custom_label) "\n\nIf this test should pass, replace \"toBe\" with \"toEqual\" or \"toStrictEqual\"" else "") ++ "\n\nExpected: {any}\n" ++ "Received: serializes to the same string\n"; - this.throw(globalThis, signature, fmt, .{right.toFmt(&formatter)}); - return .zero; + return this.throw(globalThis, signature, fmt, .{right.toFmt(&formatter)}); } if (right.isString() and left.isString()) { @@ -558,15 +548,13 @@ pub const Expect = struct { .globalThis = globalThis, .not = not, }; - this.throw(globalThis, signature, "\n\n{any}\n", .{diff_format}); - return .zero; + return this.throw(globalThis, signature, "\n\n{any}\n", .{diff_format}); } - this.throw(globalThis, signature, "\n\nExpected: {any}\nReceived: {any}\n", .{ + return this.throw(globalThis, signature, "\n\nExpected: {any}\nReceived: {any}\n", .{ right.toFmt(&formatter), left.toFmt(&formatter), }); - return .zero; }, } } @@ -634,15 +622,13 @@ pub const Expect = struct { if (not) { const expected_line = "Expected length: not {d}\n"; const signature = comptime getSignature("toHaveLength", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line, .{expected_length}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line, .{expected_length}); } const expected_line = "Expected length: {d}\n"; const received_line = "Received length: {d}\n"; const signature = comptime getSignature("toHaveLength", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_length, actual_length }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_length, actual_length }); } pub fn toBeOneOf( @@ -719,15 +705,13 @@ pub const Expect = struct { const received_fmt = list_value.toFmt(&formatter); const expected_line = "Expected to not be one of: {any}\nReceived: {any}\n"; const signature = comptime getSignature("toBeOneOf", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line, .{ received_fmt, expected_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line, .{ received_fmt, expected_fmt }); } const expected_line = "Expected to be one of: {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeOneOf", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ value_fmt, expected_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ value_fmt, expected_fmt }); } pub fn toContain( @@ -816,15 +800,13 @@ pub const Expect = struct { const received_fmt = value.toFmt(&formatter); const expected_line = "Expected to not contain: {any}\nReceived: {any}\n"; const signature = comptime getSignature("toContain", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line, .{ expected_fmt, received_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line, .{ expected_fmt, received_fmt }); } const expected_line = "Expected to contain: {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toContain", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } pub fn toContainKey( @@ -870,15 +852,13 @@ pub const Expect = struct { const received_fmt = value.toFmt(&formatter); const expected_line = "Expected to not contain: {any}\nReceived: {any}\n"; const signature = comptime getSignature("toContainKey", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line, .{ expected_fmt, received_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line, .{ expected_fmt, received_fmt }); } const expected_line = "Expected to contain: {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toContainKey", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } pub fn toContainKeys( @@ -942,15 +922,13 @@ pub const Expect = struct { const received_fmt = value.toFmt(&formatter); const expected_line = "Expected to not contain: {any}\nReceived: {any}\n"; const signature = comptime getSignature("toContainKeys", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line, .{ expected_fmt, received_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line, .{ expected_fmt, received_fmt }); } const expected_line = "Expected to contain: {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toContainKeys", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } pub fn toContainAllKeys( @@ -1009,15 +987,13 @@ pub const Expect = struct { const received_fmt = keys.toFmt(&formatter); const expected_line = "Expected to not contain all keys: {any}\nReceived: {any}\n"; const fmt = "\n\n" ++ expected_line; - this.throw(globalObject, comptime getSignature("toContainAllKeys", "expected", true), fmt, .{ expected_fmt, received_fmt }); - return .zero; + return this.throw(globalObject, comptime getSignature("toContainAllKeys", "expected", true), fmt, .{ expected_fmt, received_fmt }); } const expected_line = "Expected to contain all keys: {any}\n"; const received_line = "Received: {any}\n"; const fmt = "\n\n" ++ expected_line ++ received_line; - this.throw(globalObject, comptime getSignature("toContainAllKeys", "expected", false), fmt, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalObject, comptime getSignature("toContainAllKeys", "expected", false), fmt, .{ expected_fmt, value_fmt }); } pub fn toContainAnyKeys( @@ -1076,15 +1052,13 @@ pub const Expect = struct { const received_fmt = value.toFmt(&formatter); const expected_line = "Expected to not contain: {any}\nReceived: {any}\n"; const signature = comptime getSignature("toContainAnyKeys", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line, .{ expected_fmt, received_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line, .{ expected_fmt, received_fmt }); } const expected_line = "Expected to contain: {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toContainAnyKeys", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } pub fn toContainValue( @@ -1132,15 +1106,13 @@ pub const Expect = struct { const received_fmt = value.toFmt(&formatter); const expected_line = "Expected to not contain: {any}\nReceived: {any}\n"; const fmt = "\n\n" ++ expected_line; - this.throw(globalObject, comptime getSignature("toContainValue", "expected", true), fmt, .{ expected_fmt, received_fmt }); - return .zero; + return this.throw(globalObject, comptime getSignature("toContainValue", "expected", true), fmt, .{ expected_fmt, received_fmt }); } const expected_line = "Expected to contain: {any}\n"; const received_line = "Received: {any}\n"; const fmt = "\n\n" ++ expected_line ++ received_line; - this.throw(globalObject, comptime getSignature("toContainValue", "expected", false), fmt, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalObject, comptime getSignature("toContainValue", "expected", false), fmt, .{ expected_fmt, value_fmt }); } pub fn toContainValues( @@ -1198,15 +1170,13 @@ pub const Expect = struct { const received_fmt = value.toFmt(&formatter); const expected_line = "Expected to not contain: {any}\nReceived: {any}\n"; const fmt = "\n\n" ++ expected_line; - this.throw(globalObject, comptime getSignature("toContainValues", "expected", true), fmt, .{ expected_fmt, received_fmt }); - return .zero; + return this.throw(globalObject, comptime getSignature("toContainValues", "expected", true), fmt, .{ expected_fmt, received_fmt }); } const expected_line = "Expected to contain: {any}\n"; const received_line = "Received: {any}\n"; const fmt = "\n\n" ++ expected_line ++ received_line; - this.throw(globalObject, comptime getSignature("toContainValues", "expected", false), fmt, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalObject, comptime getSignature("toContainValues", "expected", false), fmt, .{ expected_fmt, value_fmt }); } pub fn toContainAllValues( @@ -1270,15 +1240,13 @@ pub const Expect = struct { const received_fmt = value.toFmt(&formatter); const expected_line = "Expected to not contain all values: {any}\nReceived: {any}\n"; const fmt = "\n\n" ++ expected_line; - this.throw(globalObject, comptime getSignature("toContainAllValues", "expected", true), fmt, .{ expected_fmt, received_fmt }); - return .zero; + return this.throw(globalObject, comptime getSignature("toContainAllValues", "expected", true), fmt, .{ expected_fmt, received_fmt }); } const expected_line = "Expected to contain all values: {any}\n"; const received_line = "Received: {any}\n"; const fmt = "\n\n" ++ expected_line ++ received_line; - this.throw(globalObject, comptime getSignature("toContainAllValues", "expected", false), fmt, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalObject, comptime getSignature("toContainAllValues", "expected", false), fmt, .{ expected_fmt, value_fmt }); } pub fn toContainAnyValues( @@ -1336,15 +1304,13 @@ pub const Expect = struct { const received_fmt = value.toFmt(&formatter); const expected_line = "Expected to not contain any of the following values: {any}\nReceived: {any}\n"; const fmt = "\n\n" ++ expected_line; - this.throw(globalObject, comptime getSignature("toContainAnyValues", "expected", true), fmt, .{ expected_fmt, received_fmt }); - return .zero; + return this.throw(globalObject, comptime getSignature("toContainAnyValues", "expected", true), fmt, .{ expected_fmt, received_fmt }); } const expected_line = "Expected to contain any of the following values: {any}\n"; const received_line = "Received: {any}\n"; const fmt = "\n\n" ++ expected_line ++ received_line; - this.throw(globalObject, comptime getSignature("toContainAnyValues", "expected", false), fmt, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalObject, comptime getSignature("toContainAnyValues", "expected", false), fmt, .{ expected_fmt, value_fmt }); } pub fn toContainEqual( @@ -1441,15 +1407,13 @@ pub const Expect = struct { if (not) { const expected_line = "Expected to not contain: {any}\n"; const signature = comptime getSignature("toContainEqual", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line, .{expected_fmt}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line, .{expected_fmt}); } const expected_line = "Expected to contain: {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toContainEqual", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } pub fn toBeTruthy(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -1474,14 +1438,12 @@ pub const Expect = struct { if (not) { const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeTruthy", "", true); - this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); } const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeTruthy", "", false); - this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); } pub fn toBeUndefined(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -1504,14 +1466,12 @@ pub const Expect = struct { if (not) { const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeUndefined", "", true); - this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); } const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeUndefined", "", false); - this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); } pub fn toBeNaN(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -1538,14 +1498,12 @@ pub const Expect = struct { if (not) { const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeNaN", "", true); - this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); } const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeNaN", "", false); - this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); } pub fn toBeNull(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -1567,14 +1525,12 @@ pub const Expect = struct { if (not) { const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeNull", "", true); - this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); } const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeNull", "", false); - this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); } pub fn toBeDefined(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -1596,14 +1552,12 @@ pub const Expect = struct { if (not) { const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeDefined", "", true); - this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); } const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeDefined", "", false); - this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); } pub fn toBeFalsy(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -1630,14 +1584,12 @@ pub const Expect = struct { if (not) { const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeFalsy", "", true); - this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); } const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeFalsy", "", false); - this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); } pub fn toEqual(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -1672,13 +1624,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toEqual", "expected", true); - this.throw(globalThis, signature, "\n\n{any}\n", .{diff_formatter}); - return .zero; + return this.throw(globalThis, signature, "\n\n{any}\n", .{diff_formatter}); } const signature = comptime getSignature("toEqual", "expected", false); - this.throw(globalThis, signature, "\n\n{any}\n", .{diff_formatter}); - return .zero; + return this.throw(globalThis, signature, "\n\n{any}\n", .{diff_formatter}); } pub fn toStrictEqual(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -1708,13 +1658,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toStrictEqual", "expected", true); - this.throw(globalThis, signature, "\n\n{any}\n", .{diff_formatter}); - return .zero; + return this.throw(globalThis, signature, "\n\n{any}\n", .{diff_formatter}); } const signature = comptime getSignature("toStrictEqual", "expected", false); - this.throw(globalThis, signature, "\n\n{any}\n", .{diff_formatter}); - return .zero; + return this.throw(globalThis, signature, "\n\n{any}\n", .{diff_formatter}); } pub fn toHaveProperty(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -1767,20 +1715,18 @@ pub const Expect = struct { if (expected_property != null) { const signature = comptime getSignature("toHaveProperty", "path, value", true); if (received_property != .zero) { - this.throw(globalThis, signature, "\n\nExpected path: {any}\n\nExpected value: not {any}\n", .{ + return this.throw(globalThis, signature, "\n\nExpected path: {any}\n\nExpected value: not {any}\n", .{ expected_property_path.toFmt(&formatter), expected_property.?.toFmt(&formatter), }); - return .zero; } } const signature = comptime getSignature("toHaveProperty", "path", true); - this.throw(globalThis, signature, "\n\nExpected path: not {any}\n\nReceived value: {any}\n", .{ + return this.throw(globalThis, signature, "\n\nExpected path: not {any}\n\nReceived value: {any}\n", .{ expected_property_path.toFmt(&formatter), received_property.toFmt(&formatter), }); - return .zero; } if (expected_property != null) { @@ -1793,22 +1739,19 @@ pub const Expect = struct { .globalThis = globalThis, }; - this.throw(globalThis, signature, "\n\n{any}\n", .{diff_format}); - return .zero; + return this.throw(globalThis, signature, "\n\n{any}\n", .{diff_format}); } const fmt = "\n\nExpected path: {any}\n\nExpected value: {any}\n\n" ++ "Unable to find property\n"; - this.throw(globalThis, signature, fmt, .{ + return this.throw(globalThis, signature, fmt, .{ expected_property_path.toFmt(&formatter), expected_property.?.toFmt(&formatter), }); - return .zero; } const signature = comptime getSignature("toHaveProperty", "path", false); - this.throw(globalThis, signature, "\n\nExpected path: {any}\n\nUnable to find property\n", .{expected_property_path.toFmt(&formatter)}); - return .zero; + return this.throw(globalThis, signature, "\n\nExpected path: {any}\n\nUnable to find property\n", .{expected_property_path.toFmt(&formatter)}); } pub fn toBeEven(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -1855,14 +1798,12 @@ pub const Expect = struct { if (not) { const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeEven", "", true); - this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); } const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeEven", "", false); - this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); } pub fn toBeGreaterThan(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -1916,15 +1857,13 @@ pub const Expect = struct { const expected_line = "Expected: not \\> {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeGreaterThan", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } const expected_line = "Expected: \\> {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeGreaterThan", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } pub fn toBeGreaterThanOrEqual(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -1978,15 +1917,13 @@ pub const Expect = struct { const expected_line = "Expected: not \\>= {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeGreaterThanOrEqual", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } const expected_line = "Expected: \\>= {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeGreaterThanOrEqual", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } pub fn toBeLessThan(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -2040,15 +1977,13 @@ pub const Expect = struct { const expected_line = "Expected: not \\< {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeLessThan", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } const expected_line = "Expected: \\< {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeLessThan", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } pub fn toBeLessThanOrEqual(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -2102,15 +2037,13 @@ pub const Expect = struct { const expected_line = "Expected: not \\<= {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeLessThanOrEqual", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } const expected_line = "Expected: \\<= {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeLessThanOrEqual", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } pub fn toBeCloseTo(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -2186,13 +2119,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBeCloseTo", "expected, precision", true); - this.throw(globalThis, signature, suffix_fmt, .{ expected_fmt, received_fmt, precision, expected_diff, actual_diff }); - return .zero; + return this.throw(globalThis, signature, suffix_fmt, .{ expected_fmt, received_fmt, precision, expected_diff, actual_diff }); } const signature = comptime getSignature("toBeCloseTo", "expected, precision", false); - this.throw(globalThis, signature, suffix_fmt, .{ expected_fmt, received_fmt, precision, expected_diff, actual_diff }); - return .zero; + return this.throw(globalThis, signature, suffix_fmt, .{ expected_fmt, received_fmt, precision, expected_diff, actual_diff }); } pub fn toBeOdd(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -2237,14 +2168,12 @@ pub const Expect = struct { if (not) { const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeOdd", "", true); - this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); } const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeOdd", "", false); - this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ received_line, .{value_fmt}); } pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -2352,17 +2281,15 @@ pub const Expect = struct { const name = try err.getTruthyComptime(globalThis, "name") orelse JSValue.undefined; const message = try err.getTruthyComptime(globalThis, "message") orelse JSValue.undefined; const fmt = signature_no_args ++ "\n\nError name: {any}\nError message: {any}\n"; - globalThis.throwPretty(fmt, .{ + return globalThis.throwPretty(fmt, .{ name.toFmt(&formatter), message.toFmt(&formatter), }); - return .zero; } // non error thrown const fmt = signature_no_args ++ "\n\nThrown value: {any}\n"; - globalThis.throwPretty(fmt, .{result.toFmt(&formatter)}); - return .zero; + return globalThis.throwPretty(fmt, .{result.toFmt(&formatter)}); } if (expected_value.isString()) { @@ -2384,11 +2311,10 @@ pub const Expect = struct { if (!strings.contains(received_slice.slice(), expected_slice.slice())) return .undefined; } - this.throw(globalThis, signature, "\n\nExpected substring: not {any}\nReceived message: {any}\n", .{ + return this.throw(globalThis, signature, "\n\nExpected substring: not {any}\nReceived message: {any}\n", .{ expected_value.toFmt(&formatter), received_message.toFmt(&formatter), }); - return .zero; } if (expected_value.isRegExp()) { @@ -2406,11 +2332,10 @@ pub const Expect = struct { if (!matches.toBoolean()) return .undefined; } - this.throw(globalThis, signature, "\n\nExpected pattern: not {any}\nReceived message: {any}\n", .{ + return this.throw(globalThis, signature, "\n\nExpected pattern: not {any}\nReceived message: {any}\n", .{ expected_value.toFmt(&formatter), received_message.toFmt(&formatter), }); - return .zero; } if (expected_value.fastGet(globalThis, .message)) |expected_message| { @@ -2425,8 +2350,7 @@ pub const Expect = struct { // no partial match for this case if (!expected_message.isSameValue(received_message, globalThis)) return .undefined; - this.throw(globalThis, signature, "\n\nExpected message: not {any}\n", .{expected_message.toFmt(&formatter)}); - return .zero; + return this.throw(globalThis, signature, "\n\nExpected message: not {any}\n", .{expected_message.toFmt(&formatter)}); } if (!result.isInstanceOf(globalThis, expected_value)) return .undefined; @@ -2434,8 +2358,7 @@ pub const Expect = struct { var expected_class = ZigString.Empty; expected_value.getClassName(globalThis, &expected_class); const received_message = result.fastGet(globalThis, .message) orelse .undefined; - this.throw(globalThis, signature, "\n\nExpected constructor: not {s}\n\nReceived message: {any}\n", .{ expected_class, received_message.toFmt(&formatter) }); - return .zero; + return this.throw(globalThis, signature, "\n\nExpected constructor: not {s}\n\nReceived message: {any}\n", .{ expected_class, received_message.toFmt(&formatter) }); } if (did_throw) { @@ -2472,15 +2395,12 @@ pub const Expect = struct { if (_received_message) |received_message| { const expected_value_fmt = expected_value.toFmt(&formatter); const received_message_fmt = received_message.toFmt(&formatter); - this.throw(globalThis, signature, "\n\n" ++ "Expected substring: {any}\nReceived message: {any}\n", .{ expected_value_fmt, received_message_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Expected substring: {any}\nReceived message: {any}\n", .{ expected_value_fmt, received_message_fmt }); } const expected_fmt = expected_value.toFmt(&formatter); const received_fmt = result.toFmt(&formatter); - this.throw(globalThis, signature, "\n\n" ++ "Expected substring: {any}\nReceived value: {any}", .{ expected_fmt, received_fmt }); - - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Expected substring: {any}\nReceived value: {any}", .{ expected_fmt, received_fmt }); } if (expected_value.isRegExp()) { @@ -2500,16 +2420,13 @@ pub const Expect = struct { const received_message_fmt = received_message.toFmt(&formatter); const signature = comptime getSignature("toThrow", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ "Expected pattern: {any}\nReceived message: {any}\n", .{ expected_value_fmt, received_message_fmt }); - - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Expected pattern: {any}\nReceived message: {any}\n", .{ expected_value_fmt, received_message_fmt }); } const expected_fmt = expected_value.toFmt(&formatter); const received_fmt = result.toFmt(&formatter); const signature = comptime getSignature("toThrow", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ "Expected pattern: {any}\nReceived value: {any}", .{ expected_fmt, received_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Expected pattern: {any}\nReceived value: {any}", .{ expected_fmt, received_fmt }); } if (Expect.isAsymmetricMatcher(expected_value)) { @@ -2527,8 +2444,7 @@ pub const Expect = struct { var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true }; const received_fmt = result.toFmt(&formatter); const expected_fmt = expected_value.toFmt(&formatter); - this.throw(globalThis, signature, "\n\nExpected value: {any}\nReceived value: {any}\n", .{ expected_fmt, received_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\nExpected value: {any}\nReceived value: {any}\n", .{ expected_fmt, received_fmt }); } // If it's not an object, we are going to crash here. @@ -2547,14 +2463,12 @@ pub const Expect = struct { if (_received_message) |received_message| { const expected_fmt = expected_message.toFmt(&formatter); const received_fmt = received_message.toFmt(&formatter); - this.throw(globalThis, signature, "\n\nExpected message: {any}\nReceived message: {any}\n", .{ expected_fmt, received_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\nExpected message: {any}\nReceived message: {any}\n", .{ expected_fmt, received_fmt }); } const expected_fmt = expected_message.toFmt(&formatter); const received_fmt = result.toFmt(&formatter); - this.throw(globalThis, signature, "\n\nExpected message: {any}\nReceived value: {any}\n", .{ expected_fmt, received_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\nExpected message: {any}\nReceived value: {any}\n", .{ expected_fmt, received_fmt }); } if (result.isInstanceOf(globalThis, expected_value)) return .undefined; @@ -2572,23 +2486,21 @@ pub const Expect = struct { const message_fmt = fmt ++ "Received message: {any}\n"; const received_message_fmt = received_message.toFmt(&formatter); - globalThis.throwPretty(message_fmt, .{ + return globalThis.throwPretty(message_fmt, .{ expected_class, received_class, received_message_fmt, }); - return .zero; } const received_fmt = result.toFmt(&formatter); const value_fmt = fmt ++ "Received value: {any}\n"; - globalThis.throwPretty(value_fmt, .{ + return globalThis.throwPretty(value_fmt, .{ expected_class, received_class, received_fmt, }); - return .zero; } // did not throw @@ -2598,35 +2510,30 @@ pub const Expect = struct { if (expected_value == .zero or expected_value.isUndefined()) { const signature = comptime getSignature("toThrow", "", false); - this.throw(globalThis, signature, "\n\n" ++ received_line, .{result.toFmt(&formatter)}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ received_line, .{result.toFmt(&formatter)}); } const signature = comptime getSignature("toThrow", "expected", false); if (expected_value.isString()) { const expected_fmt = "\n\nExpected substring: {any}\n\n" ++ received_line; - this.throw(globalThis, signature, expected_fmt, .{ expected_value.toFmt(&formatter), result.toFmt(&formatter) }); - return .zero; + return this.throw(globalThis, signature, expected_fmt, .{ expected_value.toFmt(&formatter), result.toFmt(&formatter) }); } if (expected_value.isRegExp()) { const expected_fmt = "\n\nExpected pattern: {any}\n\n" ++ received_line; - this.throw(globalThis, signature, expected_fmt, .{ expected_value.toFmt(&formatter), result.toFmt(&formatter) }); - return .zero; + return this.throw(globalThis, signature, expected_fmt, .{ expected_value.toFmt(&formatter), result.toFmt(&formatter) }); } if (expected_value.fastGet(globalThis, .message)) |expected_message| { const expected_fmt = "\n\nExpected message: {any}\n\n" ++ received_line; - this.throw(globalThis, signature, expected_fmt, .{ expected_message.toFmt(&formatter), result.toFmt(&formatter) }); - return .zero; + return this.throw(globalThis, signature, expected_fmt, .{ expected_message.toFmt(&formatter), result.toFmt(&formatter) }); } const expected_fmt = "\n\nExpected constructor: {s}\n\n" ++ received_line; var expected_class = ZigString.Empty; expected_value.getClassName(globalThis, &expected_class); - this.throw(globalThis, signature, expected_fmt, .{ expected_class, result.toFmt(&formatter) }); - return .zero; + return this.throw(globalThis, signature, expected_fmt, .{ expected_class, result.toFmt(&formatter) }); } pub fn toMatchSnapshot(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { defer this.postMatch(globalThis); @@ -2639,13 +2546,12 @@ pub const Expect = struct { const not = this.flags.not; if (not) { const signature = comptime getSignature("toMatchSnapshot", "", true); - this.throw(globalThis, signature, "\n\nMatcher error: Snapshot matchers cannot be used with not\n", .{}); + return this.throw(globalThis, signature, "\n\nMatcher error: Snapshot matchers cannot be used with not\n", .{}); } if (this.testScope() == null) { const signature = comptime getSignature("toMatchSnapshot", "", true); - this.throw(globalThis, signature, "\n\nMatcher error: Snapshot matchers cannot be used outside of a test\n", .{}); - return .zero; + return this.throw(globalThis, signature, "\n\nMatcher error: Snapshot matchers cannot be used outside of a test\n", .{}); } var hint_string: ZigString = ZigString.Empty; @@ -2662,8 +2568,7 @@ pub const Expect = struct { else => { if (!arguments[0].isObject()) { const signature = comptime getSignature("toMatchSnapshot", "properties, hint", false); - this.throw(globalThis, signature, "\n\nMatcher error: Expected properties must be an object\n", .{}); - return .zero; + return this.throw(globalThis, signature, "\n\nMatcher error: Expected properties must be an object\n", .{}); } property_matchers = arguments[0]; @@ -2681,8 +2586,7 @@ pub const Expect = struct { if (!value.isObject() and property_matchers != null) { const signature = comptime getSignature("toMatchSnapshot", "properties, hint", false); - this.throw(globalThis, signature, "\n\nMatcher error: received values must be an object when the matcher has properties\n", .{}); - return .zero; + return this.throw(globalThis, signature, "\n\nMatcher error: received values must be an object when the matcher has properties\n", .{}); } if (property_matchers) |_prop_matchers| { @@ -2695,8 +2599,7 @@ pub const Expect = struct { "\n\nReceived: {any}\n"; var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis }; - globalThis.throwPretty(fmt, .{value.toFmt(&formatter)}); - return .zero; + return globalThis.throwPretty(fmt, .{value.toFmt(&formatter)}); } } @@ -2736,8 +2639,7 @@ pub const Expect = struct { .globalThis = globalThis, }; - globalThis.throwPretty(fmt, .{diff_format}); - return .zero; + return globalThis.throwPretty(fmt, .{diff_format}); } return .undefined; @@ -2785,8 +2687,7 @@ pub const Expect = struct { const signature = comptime getSignature("toBeEmpty", "", false); const fmt = signature ++ "\n\nExpected value to be a string, object, or iterable" ++ "\n\nReceived: {any}\n"; - globalThis.throwPretty(fmt, .{value.toFmt(&formatter)}); - return .zero; + return globalThis.throwPretty(fmt, .{value.toFmt(&formatter)}); } } else if (std.math.isNan(actual_length)) { globalThis.throw("Received value has non-number length property: {}", .{actual_length}); @@ -2799,8 +2700,7 @@ pub const Expect = struct { const signature = comptime getSignature("toBeEmpty", "", true); const fmt = signature ++ "\n\nExpected value not to be a string, object, or iterable" ++ "\n\nReceived: {any}\n"; - globalThis.throwPretty(fmt, .{value.toFmt(&formatter)}); - return .zero; + return globalThis.throwPretty(fmt, .{value.toFmt(&formatter)}); } if (not) pass = !pass; @@ -2810,15 +2710,13 @@ pub const Expect = struct { const signature = comptime getSignature("toBeEmpty", "", true); const fmt = signature ++ "\n\nExpected value not to be empty" ++ "\n\nReceived: {any}\n"; - globalThis.throwPretty(fmt, .{value.toFmt(&formatter)}); - return .zero; + return globalThis.throwPretty(fmt, .{value.toFmt(&formatter)}); } const signature = comptime getSignature("toBeEmpty", "", false); const fmt = signature ++ "\n\nExpected value to be empty" ++ "\n\nReceived: {any}\n"; - globalThis.throwPretty(fmt, .{value.toFmt(&formatter)}); - return .zero; + return globalThis.throwPretty(fmt, .{value.toFmt(&formatter)}); } pub fn toBeEmptyObject(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -2840,13 +2738,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBeEmptyObject", "", true); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } const signature = comptime getSignature("toBeEmptyObject", "", false); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } pub fn toBeNil(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -2867,13 +2763,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBeNil", "", true); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } const signature = comptime getSignature("toBeNil", "", false); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } pub fn toBeArray(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -2894,13 +2788,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBeArray", "", true); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } const signature = comptime getSignature("toBeArray", "", false); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } pub fn toBeArrayOfSize(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -2937,13 +2829,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBeArrayOfSize", "", true); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } const signature = comptime getSignature("toBeArrayOfSize", "", false); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } pub fn toBeBoolean(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -2964,13 +2854,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBeBoolean", "", true); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } const signature = comptime getSignature("toBeBoolean", "", false); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } pub fn toBeTypeOf(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3038,13 +2926,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBeTypeOf", "", true); - this.throw(globalThis, signature, "\n\n" ++ "Expected type: not {any}\n" ++ "Received type: \"{s}\"\nReceived value: {any}\n", .{ expected_str, whatIsTheType, received }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Expected type: not {any}\n" ++ "Received type: \"{s}\"\nReceived value: {any}\n", .{ expected_str, whatIsTheType, received }); } const signature = comptime getSignature("toBeTypeOf", "", false); - this.throw(globalThis, signature, "\n\n" ++ "Expected type: {any}\n" ++ "Received type: \"{s}\"\nReceived value: {any}\n", .{ expected_str, whatIsTheType, received }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Expected type: {any}\n" ++ "Received type: \"{s}\"\nReceived value: {any}\n", .{ expected_str, whatIsTheType, received }); } pub fn toBeTrue(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3065,13 +2951,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBeTrue", "", true); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } const signature = comptime getSignature("toBeTrue", "", false); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } pub fn toBeFalse(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3092,13 +2976,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBeFalse", "", true); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } const signature = comptime getSignature("toBeFalse", "", false); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } pub fn toBeNumber(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3119,13 +3001,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBeNumber", "", true); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } const signature = comptime getSignature("toBeNumber", "", false); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } pub fn toBeInteger(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3146,13 +3026,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBeInteger", "", true); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } const signature = comptime getSignature("toBeInteger", "", false); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } pub fn toBeObject(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3173,13 +3051,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBeObject", "", true); - this.throw(globalThis, signature, "\n\nExpected value not to be an object" ++ "\n\nReceived: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\nExpected value not to be an object" ++ "\n\nReceived: {any}\n", .{received}); } const signature = comptime getSignature("toBeObject", "", false); - this.throw(globalThis, signature, "\n\nExpected value to be an object" ++ "\n\nReceived: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\nExpected value to be an object" ++ "\n\nReceived: {any}\n", .{received}); } pub fn toBeFinite(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3206,13 +3082,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBeFinite", "", true); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } const signature = comptime getSignature("toBeFinite", "", false); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } pub fn toBePositive(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3239,13 +3113,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBePositive", "", true); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } const signature = comptime getSignature("toBePositive", "", false); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } pub fn toBeNegative(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3272,13 +3144,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBeNegative", "", true); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } const signature = comptime getSignature("toBeNegative", "", false); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } pub fn toBeWithin(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3332,15 +3202,13 @@ pub const Expect = struct { const expected_line = "Expected: not between {any} (inclusive) and {any} (exclusive)\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeWithin", "start, end", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ start_fmt, end_fmt, received_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ start_fmt, end_fmt, received_fmt }); } const expected_line = "Expected: between {any} (inclusive) and {any} (exclusive)\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toBeWithin", "start, end", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ start_fmt, end_fmt, received_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ start_fmt, end_fmt, received_fmt }); } pub fn toEqualIgnoringWhitespace(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3415,13 +3283,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toEqualIgnoringWhitespace", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ "Expected: not {any}\n" ++ "Received: {any}\n", .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Expected: not {any}\n" ++ "Received: {any}\n", .{ expected_fmt, value_fmt }); } const signature = comptime getSignature("toEqualIgnoringWhitespace", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ "Expected: {any}\n" ++ "Received: {any}\n", .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Expected: {any}\n" ++ "Received: {any}\n", .{ expected_fmt, value_fmt }); } pub fn toBeSymbol(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3442,13 +3308,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBeSymbol", "", true); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } const signature = comptime getSignature("toBeSymbol", "", false); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } pub fn toBeFunction(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3469,13 +3333,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBeFunction", "", true); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } const signature = comptime getSignature("toBeFunction", "", false); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } pub fn toBeDate(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3496,13 +3358,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBeDate", "", true); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } const signature = comptime getSignature("toBeDate", "", false); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } pub fn toBeValidDate(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3524,13 +3384,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBeValidDate", "", true); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } const signature = comptime getSignature("toBeValidDate", "", false); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } pub fn toBeString(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3551,13 +3409,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toBeString", "", true); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } const signature = comptime getSignature("toBeString", "", false); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}\n", .{received}); } pub fn toInclude(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3605,15 +3461,13 @@ pub const Expect = struct { const expected_line = "Expected to not include: {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toInclude", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } const expected_line = "Expected to include: {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toInclude", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } pub fn toIncludeRepeated(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3695,35 +3549,31 @@ pub const Expect = struct { if (countAsNum == 0) { const expected_line = "Expected to include: {any} \n"; const signature = comptime getSignature("toIncludeRepeated", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ substring_fmt, expect_string_fmt }); + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ substring_fmt, expect_string_fmt }); } else if (countAsNum == 1) { const expected_line = "Expected not to include: {any} \n"; const signature = comptime getSignature("toIncludeRepeated", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ substring_fmt, expect_string_fmt }); + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ substring_fmt, expect_string_fmt }); } else { const expected_line = "Expected not to include: {any} {any} times \n"; const signature = comptime getSignature("toIncludeRepeated", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ substring_fmt, times_fmt, expect_string_fmt }); + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ substring_fmt, times_fmt, expect_string_fmt }); } - - return .zero; } if (countAsNum == 0) { const expected_line = "Expected to not include: {any}\n"; const signature = comptime getSignature("toIncludeRepeated", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ substring_fmt, expect_string_fmt }); + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ substring_fmt, expect_string_fmt }); } else if (countAsNum == 1) { const expected_line = "Expected to include: {any}\n"; const signature = comptime getSignature("toIncludeRepeated", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ substring_fmt, expect_string_fmt }); + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ substring_fmt, expect_string_fmt }); } else { const expected_line = "Expected to include: {any} {any} times \n"; const signature = comptime getSignature("toIncludeRepeated", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ substring_fmt, times_fmt, expect_string_fmt }); + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ substring_fmt, times_fmt, expect_string_fmt }); } - - return .zero; } pub fn toSatisfy(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3769,18 +3619,15 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toSatisfy", "expected", true); - this.throw(globalThis, signature, "\n\nExpected: not {any}\n", .{predicate.toFmt(&formatter)}); - return .zero; + return this.throw(globalThis, signature, "\n\nExpected: not {any}\n", .{predicate.toFmt(&formatter)}); } const signature = comptime getSignature("toSatisfy", "expected", false); - this.throw(globalThis, signature, "\n\nExpected: {any}\nReceived: {any}\n", .{ + return this.throw(globalThis, signature, "\n\nExpected: {any}\nReceived: {any}\n", .{ predicate.toFmt(&formatter), value.toFmt(&formatter), }); - - return .zero; } pub fn toStartWith(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3828,15 +3675,13 @@ pub const Expect = struct { const expected_line = "Expected to not start with: {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toStartWith", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } const expected_line = "Expected to start with: {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toStartWith", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } pub fn toEndWith(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3884,15 +3729,13 @@ pub const Expect = struct { const expected_line = "Expected to not end with: {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toEndWith", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } const expected_line = "Expected to end with: {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toEndWith", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } pub fn toBeInstanceOf(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3930,15 +3773,13 @@ pub const Expect = struct { const expected_line = "Expected constructor: not {any}\n"; const received_line = "Received value: {any}\n"; const signature = comptime getSignature("toBeInstanceOf", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } const expected_line = "Expected constructor: {any}\n"; const received_line = "Received value: {any}\n"; const signature = comptime getSignature("toBeInstanceOf", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } pub fn toMatch(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -3993,15 +3834,13 @@ pub const Expect = struct { const expected_line = "Expected substring or pattern: not {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toMatch", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } const expected_line = "Expected substring or pattern: {any}\n"; const received_line = "Received: {any}\n"; const signature = comptime getSignature("toMatch", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ expected_line ++ received_line, .{ expected_fmt, value_fmt }); } pub fn toHaveBeenCalled(this: *Expect, globalThis: *JSGlobalObject, callframe: *CallFrame) bun.JSError!JSValue { @@ -4028,13 +3867,11 @@ pub const Expect = struct { // handle failure if (not) { const signature = comptime getSignature("toHaveBeenCalled", "", true); - this.throw(globalThis, signature, "\n\n" ++ "Expected number of calls: 0\n" ++ "Received number of calls: {any}\n", .{calls.getLength(globalThis)}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Expected number of calls: 0\n" ++ "Received number of calls: {any}\n", .{calls.getLength(globalThis)}); } const signature = comptime getSignature("toHaveBeenCalled", "", false); - this.throw(globalThis, signature, "\n\n" ++ "Expected number of calls: \\>= 1\n" ++ "Received number of calls: {any}\n", .{calls.getLength(globalThis)}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Expected number of calls: \\>= 1\n" ++ "Received number of calls: {any}\n", .{calls.getLength(globalThis)}); } pub fn toHaveBeenCalledTimes(this: *Expect, globalThis: *JSGlobalObject, callframe: *CallFrame) bun.JSError!JSValue { @@ -4070,13 +3907,11 @@ pub const Expect = struct { // handle failure if (not) { const signature = comptime getSignature("toHaveBeenCalledTimes", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ "Expected number of calls: not {any}\n" ++ "Received number of calls: {any}\n", .{ times, calls.getLength(globalThis) }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Expected number of calls: not {any}\n" ++ "Received number of calls: {any}\n", .{ times, calls.getLength(globalThis) }); } const signature = comptime getSignature("toHaveBeenCalledTimes", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ "Expected number of calls: {any}\n" ++ "Received number of calls: {any}\n", .{ times, calls.getLength(globalThis) }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Expected number of calls: {any}\n" ++ "Received number of calls: {any}\n", .{ times, calls.getLength(globalThis) }); } pub fn toMatchObject(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame) bun.JSError!JSValue { @@ -4096,25 +3931,21 @@ pub const Expect = struct { const matcher_error = "\n\nMatcher error: received value must be a non-null object\n"; if (not) { const signature = comptime getSignature("toMatchObject", "expected", true); - this.throw(globalThis, signature, matcher_error, .{}); - return .zero; + return this.throw(globalThis, signature, matcher_error, .{}); } const signature = comptime getSignature("toMatchObject", "expected", false); - this.throw(globalThis, signature, matcher_error, .{}); - return .zero; + return this.throw(globalThis, signature, matcher_error, .{}); } if (args.len < 1 or !args[0].isObject()) { const matcher_error = "\n\nMatcher error: expected value must be a non-null object\n"; if (not) { const signature = comptime getSignature("toMatchObject", "", true); - this.throw(globalThis, signature, matcher_error, .{}); - return .zero; + return this.throw(globalThis, signature, matcher_error, .{}); } const signature = comptime getSignature("toMatchObject", "", false); - this.throw(globalThis, signature, matcher_error, .{}); - return .zero; + return this.throw(globalThis, signature, matcher_error, .{}); } const property_matchers = args[0]; @@ -4134,13 +3965,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toMatchObject", "expected", true); - this.throw(globalThis, signature, "\n\n{any}\n", .{diff_formatter}); - return .zero; + return this.throw(globalThis, signature, "\n\n{any}\n", .{diff_formatter}); } const signature = comptime getSignature("toMatchObject", "expected", false); - this.throw(globalThis, signature, "\n\n{any}\n", .{diff_formatter}); - return .zero; + return this.throw(globalThis, signature, "\n\n{any}\n", .{diff_formatter}); } pub fn toHaveBeenCalledWith(this: *Expect, globalThis: *JSGlobalObject, callframe: *CallFrame) bun.JSError!JSValue { @@ -4197,13 +4026,11 @@ pub const Expect = struct { // handle failure if (not) { const signature = comptime getSignature("toHaveBeenCalledWith", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ "Number of calls: {any}\n", .{calls.getLength(globalThis)}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Number of calls: {any}\n", .{calls.getLength(globalThis)}); } const signature = comptime getSignature("toHaveBeenCalledWith", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ "Number of calls: {any}\n", .{calls.getLength(globalThis)}); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Number of calls: {any}\n", .{calls.getLength(globalThis)}); } pub fn toHaveBeenLastCalledWith(this: *Expect, globalThis: *JSGlobalObject, callframe: *CallFrame) bun.JSError!JSValue { @@ -4259,13 +4086,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toHaveBeenLastCalledWith", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}" ++ "\n\n" ++ "Number of calls: {any}\n", .{ received_fmt, totalCalls }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}" ++ "\n\n" ++ "Number of calls: {any}\n", .{ received_fmt, totalCalls }); } const signature = comptime getSignature("toHaveBeenLastCalledWith", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ "Received: {any}" ++ "\n\n" ++ "Number of calls: {any}\n", .{ received_fmt, totalCalls }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Received: {any}" ++ "\n\n" ++ "Number of calls: {any}\n", .{ received_fmt, totalCalls }); } pub fn toHaveBeenNthCalledWith(this: *Expect, globalThis: *JSGlobalObject, callframe: *CallFrame) bun.JSError!JSValue { @@ -4326,13 +4151,11 @@ pub const Expect = struct { if (not) { const signature = comptime getSignature("toHaveBeenNthCalledWith", "expected", true); - this.throw(globalThis, signature, "\n\n" ++ "n: {any}\n" ++ "Received: {any}" ++ "\n\n" ++ "Number of calls: {any}\n", .{ nthCallNum, received_fmt, totalCalls }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "n: {any}\n" ++ "Received: {any}" ++ "\n\n" ++ "Number of calls: {any}\n", .{ nthCallNum, received_fmt, totalCalls }); } const signature = comptime getSignature("toHaveBeenNthCalledWith", "expected", false); - this.throw(globalThis, signature, "\n\n" ++ "n: {any}\n" ++ "Received: {any}" ++ "\n\n" ++ "Number of calls: {any}\n", .{ nthCallNum, received_fmt, totalCalls }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "n: {any}\n" ++ "Received: {any}" ++ "\n\n" ++ "Number of calls: {any}\n", .{ nthCallNum, received_fmt, totalCalls }); } const ReturnStatus = enum { @@ -4416,15 +4239,13 @@ pub const Expect = struct { .globalThis = globalThis, .quote_strings = true, }; - globalThis.throwPretty(fmt, .{(try times_value.get(globalThis, "value")).?.toFmt(&formatter)}); - return .zero; + return globalThis.throwPretty(fmt, .{(try times_value.get(globalThis, "value")).?.toFmt(&formatter)}); } switch (not) { inline else => |is_not| { const signature = comptime getSignature(name, "expected", is_not); - this.throw(globalThis, signature, "\n\n" ++ "Expected number of successful calls: {d}\n" ++ "Received number of calls: {d}\n", .{ return_count, total_count }); - return .zero; + return this.throw(globalThis, signature, "\n\n" ++ "Expected number of successful calls: {d}\n" ++ "Received number of calls: {d}\n", .{ return_count, total_count }); }, } } @@ -4489,8 +4310,7 @@ pub const Expect = struct { const args = callFrame.arguments_old(1).slice(); if (args.len == 0 or !args[0].isObject()) { - globalThis.throwPretty("expect.extend(matchers)\n\nExpected an object containing matchers\n", .{}); - return .zero; + return globalThis.throwPretty("expect.extend(matchers)\n\nExpected an object containing matchers\n", .{}); } var expect_proto = Expect__getPrototype(globalThis); @@ -4699,7 +4519,7 @@ pub const Expect = struct { .globalThis = globalThis, .matcher_fn = matcher_fn, }; - throwPrettyMatcherError(globalThis, bun.String.empty, matcher_name, matcher_params, .{}, "{s}", .{message_text}); + throwPrettyMatcherError(globalThis, bun.String.empty, matcher_name, matcher_params, .{}, "{s}", .{message_text}) catch {}; return false; } @@ -4998,8 +4818,7 @@ pub const ExpectStringMatching = struct { if (args.len == 0 or (!args[0].isString() and !args[0].isRegExp())) { const fmt = "expect.stringContaining(string)\n\nExpected a string or regular expression\n"; - globalThis.throwPretty(fmt, .{}); - return .zero; + return globalThis.throwPretty(fmt, .{}); } const test_value = args[0]; @@ -5034,8 +4853,7 @@ pub const ExpectCloseTo = struct { const args = callFrame.arguments_old(2).slice(); if (args.len == 0 or !args[0].isNumber()) { - globalThis.throwPretty("expect.closeTo(number, precision?)\n\nExpected a number value", .{}); - return .zero; + return globalThis.throwPretty("expect.closeTo(number, precision?)\n\nExpected a number value", .{}); } const number_value = args[0]; @@ -5044,8 +4862,7 @@ pub const ExpectCloseTo = struct { precision_value = JSValue.jsNumberFromInt32(2); // default value from jest } if (!precision_value.isNumber()) { - globalThis.throwPretty("expect.closeTo(number, precision?)\n\nPrecision must be a number or undefined", .{}); - return .zero; + return globalThis.throwPretty("expect.closeTo(number, precision?)\n\nPrecision must be a number or undefined", .{}); } const instance = globalThis.bunVM().allocator.create(ExpectCloseTo) catch { @@ -5082,8 +4899,7 @@ pub const ExpectObjectContaining = struct { if (args.len == 0 or !args[0].isObject()) { const fmt = "expect.objectContaining(object)\n\nExpected an object\n"; - globalThis.throwPretty(fmt, .{}); - return .zero; + return globalThis.throwPretty(fmt, .{}); } const object_value = args[0]; @@ -5119,8 +4935,7 @@ pub const ExpectStringContaining = struct { if (args.len == 0 or !args[0].isString()) { const fmt = "expect.stringContaining(string)\n\nExpected a string\n"; - globalThis.throwPretty(fmt, .{}); - return .zero; + return globalThis.throwPretty(fmt, .{}); } const string_value = args[0]; @@ -5161,8 +4976,7 @@ pub const ExpectAny = struct { constructor.ensureStillAlive(); if (!constructor.isConstructor()) { const fmt = "expect.any(constructor)\n\nExpected a constructor\n"; - globalThis.throwPretty(fmt, .{}); - return error.JSError; + return globalThis.throwPretty(fmt, .{}); } const asymmetric_matcher_constructor_type = try Expect.Flags.AsymmetricMatcherConstructorType.fromJS(globalThis, constructor); @@ -5210,8 +5024,7 @@ pub const ExpectArrayContaining = struct { if (args.len == 0 or !args[0].jsType().isArray()) { const fmt = "expect.arrayContaining(array)\n\nExpected a array\n"; - globalThis.throwPretty(fmt, .{}); - return .zero; + return globalThis.throwPretty(fmt, .{}); } const array_value = args[0]; diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig index 3031cf2192..26af8a9848 100644 --- a/src/bun.js/test/jest.zig +++ b/src/bun.js/test/jest.zig @@ -1711,8 +1711,7 @@ inline fn createScope( const args = arguments.slice(); if (args.len == 0) { - globalThis.throwPretty("{s} expects a description or function", .{signature}); - return .zero; + return globalThis.throwPretty("{s} expects a description or function", .{signature}); } var description = args[0]; @@ -1726,8 +1725,7 @@ inline fn createScope( if (function.isEmptyOrUndefinedOrNull() or !function.isCell() or !function.isCallable(globalThis.vm())) { if (tag != .todo and tag != .skip) { - globalThis.throwPretty("{s} expects a function", .{signature}); - return .zero; + return globalThis.throwPretty("{s} expects a function", .{signature}); } } @@ -1737,28 +1735,24 @@ inline fn createScope( } else if (options.isObject()) { if (try options.get(globalThis, "timeout")) |timeout| { if (!timeout.isNumber()) { - globalThis.throwPretty("{s} expects timeout to be a number", .{signature}); - return .zero; + return globalThis.throwPretty("{s} expects timeout to be a number", .{signature}); } timeout_ms = @as(u32, @intCast(@max(timeout.coerce(i32, globalThis), 0))); } if (try options.get(globalThis, "retry")) |retries| { if (!retries.isNumber()) { - globalThis.throwPretty("{s} expects retry to be a number", .{signature}); - return .zero; + return globalThis.throwPretty("{s} expects retry to be a number", .{signature}); } // TODO: retry_count = @intCast(u32, @max(retries.coerce(i32, globalThis), 0)); } if (try options.get(globalThis, "repeats")) |repeats| { if (!repeats.isNumber()) { - globalThis.throwPretty("{s} expects repeats to be a number", .{signature}); - return .zero; + return globalThis.throwPretty("{s} expects repeats to be a number", .{signature}); } // TODO: repeat_count = @intCast(u32, @max(repeats.coerce(i32, globalThis), 0)); } } else if (!options.isEmptyOrUndefinedOrNull()) { - globalThis.throwPretty("{s} expects options to be a number or object", .{signature}); - return .zero; + return globalThis.throwPretty("{s} expects options to be a number or object", .{signature}); } const parent = DescribeScope.active.?; @@ -1858,13 +1852,12 @@ inline fn createIfScope( comptime signature: string, comptime Scope: type, comptime tag: Tag, -) JSValue { +) bun.JSError!JSValue { const arguments = callframe.arguments_old(1); const args = arguments.slice(); if (args.len == 0) { - globalThis.throwPretty("{s} expects a condition", .{signature}); - return .zero; + return globalThis.throwPretty("{s} expects a condition", .{signature}); } const name = ZigString.static(property); @@ -1981,8 +1974,7 @@ fn eachBind(globalThis: *JSGlobalObject, callframe: *CallFrame) bun.JSError!JSVa const args = arguments.slice(); if (args.len < 2) { - globalThis.throwPretty("{s} a description and callback function", .{signature}); - return .zero; + return globalThis.throwPretty("{s} a description and callback function", .{signature}); } var description = args[0]; @@ -1990,8 +1982,7 @@ fn eachBind(globalThis: *JSGlobalObject, callframe: *CallFrame) bun.JSError!JSVa var options = if (args.len > 2) args[2] else .zero; if (function.isEmptyOrUndefinedOrNull() or !function.isCell() or !function.isCallable(globalThis.vm())) { - globalThis.throwPretty("{s} expects a function", .{signature}); - return .zero; + return globalThis.throwPretty("{s} expects a function", .{signature}); } var timeout_ms: u32 = std.math.maxInt(u32); @@ -2000,28 +1991,24 @@ fn eachBind(globalThis: *JSGlobalObject, callframe: *CallFrame) bun.JSError!JSVa } else if (options.isObject()) { if (try options.get(globalThis, "timeout")) |timeout| { if (!timeout.isNumber()) { - globalThis.throwPretty("{s} expects timeout to be a number", .{signature}); - return .zero; + return globalThis.throwPretty("{s} expects timeout to be a number", .{signature}); } timeout_ms = @as(u32, @intCast(@max(timeout.coerce(i32, globalThis), 0))); } if (try options.get(globalThis, "retry")) |retries| { if (!retries.isNumber()) { - globalThis.throwPretty("{s} expects retry to be a number", .{signature}); - return .zero; + return globalThis.throwPretty("{s} expects retry to be a number", .{signature}); } // TODO: retry_count = @intCast(u32, @max(retries.coerce(i32, globalThis), 0)); } if (try options.get(globalThis, "repeats")) |repeats| { if (!repeats.isNumber()) { - globalThis.throwPretty("{s} expects repeats to be a number", .{signature}); - return .zero; + return globalThis.throwPretty("{s} expects repeats to be a number", .{signature}); } // TODO: repeat_count = @intCast(u32, @max(repeats.coerce(i32, globalThis), 0)); } } else if (!options.isEmptyOrUndefinedOrNull()) { - globalThis.throwPretty("{s} expects options to be a number or object", .{signature}); - return .zero; + return globalThis.throwPretty("{s} expects options to be a number or object", .{signature}); } const parent = DescribeScope.active.?; @@ -2147,19 +2134,17 @@ inline fn createEach( comptime property: [:0]const u8, comptime signature: string, comptime is_test: bool, -) JSValue { +) bun.JSError!JSValue { const arguments = callframe.arguments_old(1); const args = arguments.slice(); if (args.len == 0) { - globalThis.throwPretty("{s} expects an array", .{signature}); - return .zero; + return globalThis.throwPretty("{s} expects an array", .{signature}); } var array = args[0]; if (array == .zero or !array.jsType().isArray()) { - globalThis.throwPretty("{s} expects an array", .{signature}); - return .zero; + return globalThis.throwPretty("{s} expects an array", .{signature}); } const allocator = getAllocator(globalThis); diff --git a/src/shell/interpreter.zig b/src/shell/interpreter.zig index a54941f028..1d40b949c1 100644 --- a/src/shell/interpreter.zig +++ b/src/shell/interpreter.zig @@ -809,8 +809,7 @@ pub const ParsedShellScript = struct { if (err == shell.ParseError.Lex) { assert(lex_result != null); const str = lex_result.?.combineErrors(shargs.arena_allocator()); - globalThis.throwPretty("{s}", .{str}); - return .zero; + return globalThis.throwPretty("{s}", .{str}); } if (parser) |*p| { @@ -818,8 +817,7 @@ pub const ParsedShellScript = struct { assert(p.errors.items.len > 0); } const errstr = p.combineErrors(); - globalThis.throwPretty("{s}", .{errstr}); - return .zero; + return globalThis.throwPretty("{s}", .{errstr}); } return globalThis.throwError(err, "failed to lex/parse shell"); diff --git a/src/shell/shell.zig b/src/shell/shell.zig index 748fdbe32c..577936c05d 100644 --- a/src/shell/shell.zig +++ b/src/shell/shell.zig @@ -4398,8 +4398,7 @@ pub const TestingAPIs = struct { if (lex_result.errors.len > 0) { const str = lex_result.combineErrors(arena.allocator()); - globalThis.throwPretty("{s}", .{str}); - return .zero; + return globalThis.throwPretty("{s}", .{str}); } var test_tokens = std.ArrayList(Test.TestToken).initCapacity(arena.allocator(), lex_result.tokens.len) catch { @@ -4475,14 +4474,12 @@ pub const TestingAPIs = struct { if (err == ParseError.Lex) { if (bun.Environment.allow_assert) assert(out_lex_result != null); const str = out_lex_result.?.combineErrors(arena.allocator()); - globalThis.throwPretty("{s}", .{str}); - return .zero; + return globalThis.throwPretty("{s}", .{str}); } if (out_parser) |*p| { const errstr = p.combineErrors(); - globalThis.throwPretty("{s}", .{errstr}); - return .zero; + return globalThis.throwPretty("{s}", .{errstr}); } return globalThis.throwError(err, "failed to lex/parse shell");