Compare commits

...

2 Commits

Author SHA1 Message Date
autofix-ci[bot]
fa299b2963 [autofix.ci] apply automated fixes 2025-09-24 20:59:35 +00:00
pfg
4542b1f816 migrate all jest errors to use jest printer 2025-09-24 13:57:17 -07:00
67 changed files with 217 additions and 371 deletions

View File

@@ -1976,6 +1976,40 @@ pub const JSValue = enum(i64) {
};
}
pub const JestPrettyFormatter = struct {
value: JSValue,
globalObject: *jsc.JSGlobalObject,
pub fn format(self: JestPrettyFormatter, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void {
const vals = [_]JSValue{self.value};
try JestPrettyFormat.format(
.Debug,
self.globalObject,
&vals,
1,
@TypeOf(writer),
@TypeOf(writer),
writer,
.{
.enable_colors = false,
.add_newline = false,
.flush = false,
.quote_strings = true,
},
);
}
};
pub fn toJestPrettyFormat(
this: JSValue,
globalObject: *jsc.JSGlobalObject,
) JestPrettyFormatter {
return JestPrettyFormatter{
.value = this,
.globalObject = globalObject,
};
}
/// Check if the JSValue is either a signed 32-bit integer or a double and
/// return the value as a f64
///

View File

@@ -186,10 +186,8 @@ pub const Expect = struct {
.resolves => {},
.rejects => {
if (!silent) {
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const message = "Expected promise that rejects<r>\nReceived promise that resolved: <red>{any}<r>\n";
return 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.toJestPrettyFormat(globalThis)});
}
return error.JSError;
},
@@ -199,10 +197,8 @@ pub const Expect = struct {
.rejects => {},
.resolves => {
if (!silent) {
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const message = "Expected promise that resolves<r>\nReceived promise that rejected: <red>{any}<r>\n";
return 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.toJestPrettyFormat(globalThis)});
}
return error.JSError;
},
@@ -215,10 +211,8 @@ pub const Expect = struct {
return newValue;
} else {
if (!silent) {
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const message = "Expected promise<r>\nReceived: <red>{any}<r>\n";
return 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.toJestPrettyFormat(globalThis)});
}
return error.JSError;
}
@@ -793,16 +787,12 @@ pub const Expect = struct {
const fmt = signature ++ "\n\nExpected <green>propertyMatchers<r> to match properties from received object" ++
"\n\nReceived: {any}\n";
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis };
defer formatter.deinit();
return globalThis.throwPretty(fmt, .{value.toFmt(&formatter)});
return globalThis.throwPretty(fmt, .{value.toJestPrettyFormat(globalThis)});
}
}
value.jestSnapshotPrettyFormat(pretty_value, globalThis) catch {
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis };
defer formatter.deinit();
return globalThis.throw("Failed to pretty format value: {s}", .{value.toFmt(&formatter)});
return globalThis.throw("Failed to pretty format value: {s}", .{value.toJestPrettyFormat(globalThis)});
};
}
pub fn snapshot(this: *Expect, globalThis: *JSGlobalObject, value: JSValue, property_matchers: ?JSValue, hint: []const u8, comptime fn_name: []const u8) bun.JSError!JSValue {
@@ -811,8 +801,6 @@ pub const Expect = struct {
try this.matchAndFmtSnapshot(globalThis, value, property_matchers, &pretty_value, fn_name);
const existing_value = Jest.runner.?.snapshots.getOrPut(this, pretty_value.slice(), hint) catch |err| {
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis };
defer formatter.deinit();
const buntest = this.bunTest() orelse return globalThis.throw("Snapshot matchers cannot be used outside of a test", .{});
const test_file_path = Jest.runner.?.files.get(buntest.file_id).source.path.text;
return switch (err) {
@@ -822,7 +810,7 @@ pub const Expect = struct {
error.SyntaxError, error.ParseError => globalThis.throw("Failed to parse snapshot file for: {s}", .{test_file_path}),
error.SnapshotInConcurrentGroup => globalThis.throw("Snapshot matchers are not supported in concurrent tests", .{}),
error.TestNotActive => globalThis.throw("Snapshot matchers are not supported after the test has finished executing", .{}),
else => globalThis.throw("Failed to snapshot value: {any}", .{value.toFmt(&formatter)}),
else => globalThis.throw("Failed to snapshot value: {any}", .{value.toJestPrettyFormat(globalThis)}),
};
};
@@ -984,16 +972,13 @@ pub const Expect = struct {
fn throwInvalidMatcherError(globalThis: *JSGlobalObject, matcher_name: bun.String, result: JSValue) bun.JSError {
@branchHint(.cold);
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const fmt =
"Unexpected return from matcher function `{s}`.\n" ++
"Matcher functions should return an object in the following format:\n" ++
" {{message?: string | function, pass: boolean}}\n" ++
"'{any}' was returned";
const err = switch (Output.enable_ansi_colors) {
inline else => |colors| globalThis.createErrorInstance(Output.prettyFmt(fmt, colors), .{ matcher_name, result.toFmt(&formatter) }),
inline else => |colors| globalThis.createErrorInstance(Output.prettyFmt(fmt, colors), .{ matcher_name, result.toJestPrettyFormat(globalThis) }),
};
err.put(globalThis, ZigString.static("name"), bun.String.static("InvalidMatcherError").toJS(globalThis));
return globalThis.throwValue(err);
@@ -1169,14 +1154,12 @@ pub const Expect = struct {
const expected: JSValue = arguments[0];
if (!expected.isNumber()) {
var fmt = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
return globalThis.throw("Expected value must be a non-negative integer: {any}", .{expected.toFmt(&fmt)});
return globalThis.throw("Expected value must be a non-negative integer: {any}", .{expected.toJestPrettyFormat(globalThis)});
}
const expected_assertions: f64 = try expected.toNumber(globalThis);
if (@round(expected_assertions) != expected_assertions or std.math.isInf(expected_assertions) or std.math.isNan(expected_assertions) or expected_assertions < 0 or expected_assertions > std.math.maxInt(u32)) {
var fmt = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
return globalThis.throw("Expected value must be a non-negative integer: {any}", .{expected.toFmt(&fmt)});
return globalThis.throw("Expected value must be a non-negative integer: {any}", .{expected.toJestPrettyFormat(globalThis)});
}
const unsigned_expected_assertions: u32 = @intFromFloat(expected_assertions);
@@ -1824,9 +1807,7 @@ pub const ExpectMatcherUtils = struct {
}
}
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
try writer.print("{}", .{value.toFmt(&formatter)});
try writer.print("{}", .{value.toJestPrettyFormat(globalThis)});
if (comptime color_or_null) |_| {
if (Output.enable_ansi_colors) {
@@ -1964,9 +1945,7 @@ pub const mock = struct {
pub fn jestMockIterator(globalThis: *JSGlobalObject, value: bun.jsc.JSValue) bun.JSError!bun.jsc.JSArrayIterator {
const returns: bun.jsc.JSValue = try bun.cpp.JSMockFunction__getReturns(globalThis, value);
if (!returns.jsType().isArray()) {
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
return globalThis.throw("Expected value must be a mock function: {any}", .{value.toFmt(&formatter)});
return globalThis.throw("Expected value must be a mock function: {any}", .{value.toJestPrettyFormat(globalThis)});
}
return try returns.arrayIterator(globalThis);
@@ -1977,9 +1956,7 @@ pub const mock = struct {
if (try ReturnStatus.Map.fromJS(globalThis, type_string)) |val| return val;
}
}
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
return globalThis.throw("Expected value must be a mock function with returns: {any}", .{value.toFmt(&formatter)});
return globalThis.throw("Expected value must be a mock function with returns: {any}", .{value.toJestPrettyFormat(globalThis)});
}
pub fn jestMockReturnObject_value(globalThis: *JSGlobalObject, value: bun.jsc.JSValue) bun.JSError!JSValue {
return (try value.get(globalThis, "value")) orelse .js_undefined;
@@ -1988,7 +1965,6 @@ pub const mock = struct {
pub const AllCallsWithArgsFormatter = struct {
globalThis: *JSGlobalObject,
calls: JSValue,
formatter: *jsc.ConsoleObject.Formatter,
pub fn format(self: @This(), comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void {
var printed_once = false;
@@ -2005,7 +1981,7 @@ pub const mock = struct {
try writer.print(" {d: >4}: ", .{i + 1});
const call_args = try self.calls.getIndex(self.globalThis, @intCast(i));
try writer.print("{any}", .{call_args.toFmt(self.formatter)});
try writer.print("{any}", .{call_args.toJestPrettyFormat(self.globalThis)});
}
}
};
@@ -2022,7 +1998,6 @@ pub const mock = struct {
pub const AllCallsFormatter = struct {
globalThis: *JSGlobalObject,
returns: JSValue,
formatter: *jsc.ConsoleObject.Formatter,
pub fn format(self: @This(), comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void {
var printed_once = false;
@@ -2041,11 +2016,11 @@ pub const mock = struct {
const value = try jestMockReturnObject_value(self.globalThis, item);
switch (try jestMockReturnObject_type(self.globalThis, item)) {
.@"return" => {
try writer.print("{any}", .{value.toFmt(self.formatter)});
try writer.print("{any}", .{value.toJestPrettyFormat(self.globalThis)});
num_returns += 1;
},
.throw => {
try writer.print("function call threw an error: {any}", .{value.toFmt(self.formatter)});
try writer.print("function call threw an error: {any}", .{value.toJestPrettyFormat(self.globalThis)});
},
.incomplete => {
try writer.print("<incomplete call>", .{});
@@ -2058,7 +2033,6 @@ pub const mock = struct {
pub const SuccessfulReturnsFormatter = struct {
globalThis: *JSGlobalObject,
successful_returns: *const std.ArrayList(JSValue),
formatter: *jsc.ConsoleObject.Formatter,
pub fn format(self: @This(), comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void {
const len = self.successful_returns.items.len;
@@ -2071,7 +2045,7 @@ pub const mock = struct {
printed_once = true;
try writer.print(" {d: >4}: ", .{i});
try writer.print("{any}", .{val.toFmt(self.formatter)});
try writer.print("{any}", .{val.toJestPrettyFormat(self.globalThis)});
}
}
};

View File

@@ -25,14 +25,12 @@ pub fn toBe(
if (pass) return .js_undefined;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
switch (this.custom_label.isEmpty()) {
inline else => |has_custom_label| {
if (not) {
const signature = comptime getSignature("toBe", "<green>expected<r>", true);
return this.throw(globalThis, signature, "\n\nExpected: not <green>{any}<r>\n", .{right.toFmt(&formatter)});
return this.throw(globalThis, signature, "\n\nExpected: not <green>{any}<r>\n", .{right.toJestPrettyFormat(globalThis)});
}
const signature = comptime getSignature("toBe", "<green>expected<r>", false);
@@ -41,7 +39,7 @@ pub fn toBe(
(if (!has_custom_label) "\n\n<d>If this test should pass, replace \"toBe\" with \"toEqual\" or \"toStrictEqual\"<r>" else "") ++
"\n\nExpected: <green>{any}<r>\n" ++
"Received: serializes to the same string\n";
return this.throw(globalThis, signature, fmt, .{right.toFmt(&formatter)});
return this.throw(globalThis, signature, fmt, .{right.toJestPrettyFormat(globalThis)});
}
if (right.isString() and left.isString()) {
@@ -55,8 +53,8 @@ pub fn toBe(
}
return this.throw(globalThis, signature, "\n\nExpected: <green>{any}<r>\nReceived: <red>{any}<r>\n", .{
right.toFmt(&formatter),
left.toFmt(&formatter),
right.toJestPrettyFormat(globalThis),
left.toJestPrettyFormat(globalThis),
});
},
}

View File

@@ -11,9 +11,7 @@ pub fn toBeArray(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFra
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received = value.toFmt(&formatter);
const received = value.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toBeArray", "", true);

View File

@@ -26,9 +26,7 @@ pub fn toBeArrayOfSize(this: *Expect, globalThis: *JSGlobalObject, callFrame: *C
if (not) pass = !pass;
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received = value.toFmt(&formatter);
const received = value.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toBeArrayOfSize", "", true);

View File

@@ -11,9 +11,7 @@ pub fn toBeBoolean(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallF
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received = value.toFmt(&formatter);
const received = value.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toBeBoolean", "", true);

View File

@@ -55,11 +55,8 @@ pub fn toBeCloseTo(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallF
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const expected_fmt = expected_.toFmt(&formatter);
const received_fmt = received_.toFmt(&formatter);
const expected_fmt = expected_.toJestPrettyFormat(globalThis);
const received_fmt = received_.toJestPrettyFormat(globalThis);
const expected_line = "Expected: <green>{any}<r>\n";
const received_line = "Received: <red>{any}<r>\n";

View File

@@ -11,9 +11,7 @@ pub fn toBeDate(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFram
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received = value.toFmt(&formatter);
const received = value.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toBeDate", "", true);

View File

@@ -12,9 +12,7 @@ pub fn toBeDefined(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallF
if (pass) return .js_undefined;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
if (not) {
const received_line = "Received: <red>{any}<r>\n";
const signature = comptime getSignature("toBeDefined", "", true);

View File

@@ -8,8 +8,6 @@ pub fn toBeEmpty(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFra
const not = this.flags.not;
var pass = false;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const actual_length = try value.getLengthIfPropertyExistsInternal(globalThis);
@@ -45,7 +43,7 @@ pub fn toBeEmpty(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFra
const signature = comptime getSignature("toBeEmpty", "", false);
const fmt = signature ++ "\n\nExpected value to be a string, object, or iterable" ++
"\n\nReceived: <red>{any}<r>\n";
return globalThis.throwPretty(fmt, .{value.toFmt(&formatter)});
return globalThis.throwPretty(fmt, .{value.toJestPrettyFormat(globalThis)});
}
} else if (std.math.isNan(actual_length)) {
return globalThis.throw("Received value has non-number length property: {}", .{actual_length});
@@ -57,7 +55,7 @@ pub fn toBeEmpty(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFra
const signature = comptime getSignature("toBeEmpty", "", true);
const fmt = signature ++ "\n\nExpected value <b>not<r> to be a string, object, or iterable" ++
"\n\nReceived: <red>{any}<r>\n";
return globalThis.throwPretty(fmt, .{value.toFmt(&formatter)});
return globalThis.throwPretty(fmt, .{value.toJestPrettyFormat(globalThis)});
}
if (not) pass = !pass;
@@ -67,13 +65,13 @@ pub fn toBeEmpty(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFra
const signature = comptime getSignature("toBeEmpty", "", true);
const fmt = signature ++ "\n\nExpected value <b>not<r> to be empty" ++
"\n\nReceived: <red>{any}<r>\n";
return globalThis.throwPretty(fmt, .{value.toFmt(&formatter)});
return globalThis.throwPretty(fmt, .{value.toJestPrettyFormat(globalThis)});
}
const signature = comptime getSignature("toBeEmpty", "", false);
const fmt = signature ++ "\n\nExpected value to be empty" ++
"\n\nReceived: <red>{any}<r>\n";
return globalThis.throwPretty(fmt, .{value.toFmt(&formatter)});
return globalThis.throwPretty(fmt, .{value.toJestPrettyFormat(globalThis)});
}
const bun = @import("bun");

View File

@@ -12,9 +12,7 @@ pub fn toBeEmptyObject(this: *Expect, globalThis: *JSGlobalObject, callFrame: *C
if (not) pass = !pass;
if (pass) return thisValue;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received = value.toFmt(&formatter);
const received = value.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toBeEmptyObject", "", true);

View File

@@ -37,9 +37,7 @@ pub fn toBeEven(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFram
if (pass) return .js_undefined;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
if (not) {
const received_line = "Received: <red>{any}<r>\n";
const signature = comptime getSignature("toBeEven", "", true);

View File

@@ -11,9 +11,7 @@ pub fn toBeFalse(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFra
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received = value.toFmt(&formatter);
const received = value.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toBeFalse", "", true);

View File

@@ -17,9 +17,7 @@ pub fn toBeFalsy(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFra
if (pass) return .js_undefined;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
if (not) {
const received_line = "Received: <red>{any}<r>\n";
const signature = comptime getSignature("toBeFalsy", "", true);

View File

@@ -17,9 +17,7 @@ pub fn toBeFinite(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFr
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received = value.toFmt(&formatter);
const received = value.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toBeFinite", "", true);

View File

@@ -11,9 +11,7 @@ pub fn toBeFunction(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Call
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received = value.toFmt(&formatter);
const received = value.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toBeFunction", "", true);

View File

@@ -41,10 +41,8 @@ pub fn toBeGreaterThan(this: *Expect, globalThis: *JSGlobalObject, callFrame: *C
if (pass) return .js_undefined;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const expected_fmt = other_value.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
const expected_fmt = other_value.toJestPrettyFormat(globalThis);
if (not) {
const expected_line = "Expected: not \\> <green>{any}<r>\n";
const received_line = "Received: <red>{any}<r>\n";

View File

@@ -41,10 +41,8 @@ pub fn toBeGreaterThanOrEqual(this: *Expect, globalThis: *JSGlobalObject, callFr
if (pass) return .js_undefined;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const expected_fmt = other_value.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
const expected_fmt = other_value.toJestPrettyFormat(globalThis);
if (not) {
const expected_line = "Expected: not \\>= <green>{any}<r>\n";
const received_line = "Received: <red>{any}<r>\n";

View File

@@ -10,12 +10,10 @@ pub fn toBeInstanceOf(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Ca
}
this.incrementExpectCallCounter();
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const expected_value = arguments[0];
if (!expected_value.isConstructor()) {
return globalThis.throw("Expected value must be a function: {any}", .{expected_value.toFmt(&formatter)});
return globalThis.throw("Expected value must be a function: {any}", .{expected_value.toJestPrettyFormat(globalThis)});
}
expected_value.ensureStillAlive();
@@ -27,8 +25,8 @@ pub fn toBeInstanceOf(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Ca
if (pass) return .js_undefined;
// handle failure
const expected_fmt = expected_value.toFmt(&formatter);
const value_fmt = value.toFmt(&formatter);
const expected_fmt = expected_value.toJestPrettyFormat(globalThis);
const value_fmt = value.toJestPrettyFormat(globalThis);
if (not) {
const expected_line = "Expected constructor: not <green>{any}<r>\n";
const received_line = "Received value: <red>{any}<r>\n";

View File

@@ -11,9 +11,7 @@ pub fn toBeInteger(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallF
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received = value.toFmt(&formatter);
const received = value.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toBeInteger", "", true);

View File

@@ -41,10 +41,8 @@ pub fn toBeLessThan(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Call
if (pass) return .js_undefined;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const expected_fmt = other_value.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
const expected_fmt = other_value.toJestPrettyFormat(globalThis);
if (not) {
const expected_line = "Expected: not \\< <green>{any}<r>\n";
const received_line = "Received: <red>{any}<r>\n";

View File

@@ -41,10 +41,8 @@ pub fn toBeLessThanOrEqual(this: *Expect, globalThis: *JSGlobalObject, callFrame
if (pass) return .js_undefined;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const expected_fmt = other_value.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
const expected_fmt = other_value.toJestPrettyFormat(globalThis);
if (not) {
const expected_line = "Expected: not \\<= <green>{any}<r>\n";
const received_line = "Received: <red>{any}<r>\n";

View File

@@ -17,9 +17,7 @@ pub fn toBeNaN(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame
if (pass) return .js_undefined;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
if (not) {
const received_line = "Received: <red>{any}<r>\n";
const signature = comptime getSignature("toBeNaN", "", true);

View File

@@ -17,9 +17,7 @@ pub fn toBeNegative(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Call
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received = value.toFmt(&formatter);
const received = value.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toBeNegative", "", true);

View File

@@ -11,9 +11,7 @@ pub fn toBeNil(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received = value.toFmt(&formatter);
const received = value.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toBeNil", "", true);

View File

@@ -12,9 +12,7 @@ pub fn toBeNull(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFram
if (pass) return .js_undefined;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
if (not) {
const received_line = "Received: <red>{any}<r>\n";
const signature = comptime getSignature("toBeNull", "", true);

View File

@@ -11,9 +11,7 @@ pub fn toBeNumber(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFr
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received = value.toFmt(&formatter);
const received = value.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toBeNumber", "", true);

View File

@@ -11,9 +11,7 @@ pub fn toBeObject(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFr
if (pass) return thisValue;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received = value.toFmt(&formatter);
const received = value.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toBeObject", "", true);

View File

@@ -35,9 +35,7 @@ pub fn toBeOdd(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame
if (pass) return .js_undefined;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
if (not) {
const received_line = "Received: <red>{any}<r>\n";
const signature = comptime getSignature("toBeOdd", "", true);

View File

@@ -64,12 +64,10 @@ pub fn toBeOneOf(
if (pass) return .js_undefined;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = list_value.toFmt(&formatter);
const expected_fmt = expected.toFmt(&formatter);
const value_fmt = list_value.toJestPrettyFormat(globalThis);
const expected_fmt = expected.toJestPrettyFormat(globalThis);
if (not) {
const received_fmt = list_value.toFmt(&formatter);
const received_fmt = list_value.toJestPrettyFormat(globalThis);
const expected_line = "Expected to not be one of: <green>{any}<r>\nReceived: <red>{any}<r>\n";
const signature = comptime getSignature("toBeOneOf", "<green>expected<r>", true);
return this.throw(globalThis, signature, "\n\n" ++ expected_line, .{ received_fmt, expected_fmt });

View File

@@ -17,9 +17,7 @@ pub fn toBePositive(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Call
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received = value.toFmt(&formatter);
const received = value.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toBePositive", "", true);

View File

@@ -11,9 +11,7 @@ pub fn toBeString(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFr
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received = value.toFmt(&formatter);
const received = value.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toBeString", "", true);

View File

@@ -11,9 +11,7 @@ pub fn toBeSymbol(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFr
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received = value.toFmt(&formatter);
const received = value.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toBeSymbol", "", true);

View File

@@ -11,9 +11,7 @@ pub fn toBeTrue(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFram
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received = value.toFmt(&formatter);
const received = value.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toBeTrue", "", true);

View File

@@ -15,9 +15,7 @@ pub fn toBeTruthy(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFr
if (pass) return .js_undefined;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
if (not) {
const received_line = "Received: <red>{any}<r>\n";
const signature = comptime getSignature("toBeTruthy", "", true);

View File

@@ -67,10 +67,8 @@ pub fn toBeTypeOf(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFr
if (not) pass = !pass;
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received = value.toFmt(&formatter);
const expected_str = expected.toFmt(&formatter);
const received = value.toJestPrettyFormat(globalThis);
const expected_str = expected.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toBeTypeOf", "", true);

View File

@@ -13,9 +13,7 @@ pub fn toBeUndefined(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Cal
if (pass) return .js_undefined;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
if (not) {
const received_line = "Received: <red>{any}<r>\n";
const signature = comptime getSignature("toBeUndefined", "", true);

View File

@@ -12,9 +12,7 @@ pub fn toBeValidDate(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Cal
if (pass) return thisValue;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received = value.toFmt(&formatter);
const received = value.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toBeValidDate", "", true);

View File

@@ -38,11 +38,9 @@ pub fn toBeWithin(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFr
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const start_fmt = startValue.toFmt(&formatter);
const end_fmt = endValue.toFmt(&formatter);
const received_fmt = value.toFmt(&formatter);
const start_fmt = startValue.toJestPrettyFormat(globalThis);
const end_fmt = endValue.toJestPrettyFormat(globalThis);
const received_fmt = value.toJestPrettyFormat(globalThis);
if (not) {
const expected_line = "Expected: not between <green>{any}<r> <d>(inclusive)<r> and <green>{any}<r> <d>(exclusive)<r>\n";

View File

@@ -76,12 +76,10 @@ pub fn toContain(
if (pass) return .js_undefined;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const expected_fmt = expected.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
const expected_fmt = expected.toJestPrettyFormat(globalThis);
if (not) {
const received_fmt = value.toFmt(&formatter);
const received_fmt = value.toJestPrettyFormat(globalThis);
const expected_line = "Expected to not contain: <green>{any}<r>\nReceived: <red>{any}<r>\n";
const signature = comptime getSignature("toContain", "<green>expected<r>", true);
return this.throw(globalThis, signature, "\n\n" ++ expected_line, .{ expected_fmt, received_fmt });

View File

@@ -46,12 +46,10 @@ pub fn toContainAllKeys(
if (pass) return thisValue;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalObject, .quote_strings = true };
defer formatter.deinit();
const value_fmt = keys.toFmt(&formatter);
const expected_fmt = expected.toFmt(&formatter);
const value_fmt = keys.toJestPrettyFormat(globalObject);
const expected_fmt = expected.toJestPrettyFormat(globalObject);
if (not) {
const received_fmt = keys.toFmt(&formatter);
const received_fmt = keys.toJestPrettyFormat(globalObject);
const expected_line = "Expected to not contain all keys: <green>{any}<r>\nReceived: <red>{any}<r>\n";
const fmt = "\n\n" ++ expected_line;
return this.throw(globalObject, comptime getSignature("toContainAllKeys", "<green>expected<r>", true), fmt, .{ expected_fmt, received_fmt });

View File

@@ -51,12 +51,10 @@ pub fn toContainAllValues(
if (pass) return thisValue;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalObject, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const expected_fmt = expected.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalObject);
const expected_fmt = expected.toJestPrettyFormat(globalObject);
if (not) {
const received_fmt = value.toFmt(&formatter);
const received_fmt = value.toJestPrettyFormat(globalObject);
const expected_line = "Expected to not contain all values: <green>{any}<r>\nReceived: <red>{any}<r>\n";
const fmt = "\n\n" ++ expected_line;
return this.throw(globalObject, comptime getSignature("toContainAllValues", "<green>expected<r>", true), fmt, .{ expected_fmt, received_fmt });

View File

@@ -42,12 +42,10 @@ pub fn toContainAnyKeys(
if (pass) return thisValue;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const expected_fmt = expected.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
const expected_fmt = expected.toJestPrettyFormat(globalThis);
if (not) {
const received_fmt = value.toFmt(&formatter);
const received_fmt = value.toJestPrettyFormat(globalThis);
const expected_line = "Expected to not contain: <green>{any}<r>\nReceived: <red>{any}<r>\n";
const signature = comptime getSignature("toContainAnyKeys", "<green>expected<r>", true);
return this.throw(globalThis, signature, "\n\n" ++ expected_line, .{ expected_fmt, received_fmt });

View File

@@ -45,12 +45,10 @@ pub fn toContainAnyValues(
if (pass) return thisValue;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalObject, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const expected_fmt = expected.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalObject);
const expected_fmt = expected.toJestPrettyFormat(globalObject);
if (not) {
const received_fmt = value.toFmt(&formatter);
const received_fmt = value.toJestPrettyFormat(globalObject);
const expected_line = "Expected to not contain any of the following values: <green>{any}<r>\nReceived: <red>{any}<r>\n";
const fmt = "\n\n" ++ expected_line;
return this.throw(globalObject, comptime getSignature("toContainAnyValues", "<green>expected<r>", true), fmt, .{ expected_fmt, received_fmt });

View File

@@ -85,10 +85,8 @@ pub fn toContainEqual(
if (pass) return thisValue;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const expected_fmt = expected.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
const expected_fmt = expected.toJestPrettyFormat(globalThis);
if (not) {
const expected_line = "Expected to not contain: <green>{any}<r>\n";
const signature = comptime getSignature("toContainEqual", "<green>expected<r>", true);

View File

@@ -17,12 +17,10 @@ pub fn toContainKey(
const expected = arguments[0];
expected.ensureStillAlive();
const value: JSValue = try this.getValue(globalThis, thisValue, "toContainKey", "<green>expected<r>");
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const not = this.flags.not;
if (!value.isObject()) {
return globalThis.throwInvalidArguments("Expected value must be an object\nReceived: {}", .{value.toFmt(&formatter)});
return globalThis.throwInvalidArguments("Expected value must be an object\nReceived: {}", .{value.toJestPrettyFormat(globalThis)});
}
var pass = try value.hasOwnPropertyValue(globalThis, expected);
@@ -32,10 +30,10 @@ pub fn toContainKey(
// handle failure
const value_fmt = value.toFmt(&formatter);
const expected_fmt = expected.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
const expected_fmt = expected.toJestPrettyFormat(globalThis);
if (not) {
const received_fmt = value.toFmt(&formatter);
const received_fmt = value.toJestPrettyFormat(globalThis);
const expected_line = "Expected to not contain: <green>{any}<r>\nReceived: <red>{any}<r>\n";
const signature = comptime getSignature("toContainKey", "<green>expected<r>", true);
return this.throw(globalThis, signature, "\n\n" ++ expected_line, .{ expected_fmt, received_fmt });

View File

@@ -47,12 +47,10 @@ pub fn toContainKeys(
if (pass) return thisValue;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const expected_fmt = expected.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
const expected_fmt = expected.toJestPrettyFormat(globalThis);
if (not) {
const received_fmt = value.toFmt(&formatter);
const received_fmt = value.toJestPrettyFormat(globalThis);
const expected_line = "Expected to not contain: <green>{any}<r>\nReceived: <red>{any}<r>\n";
const signature = comptime getSignature("toContainKeys", "<green>expected<r>", true);
return this.throw(globalThis, signature, "\n\n" ++ expected_line, .{ expected_fmt, received_fmt });

View File

@@ -36,12 +36,10 @@ pub fn toContainValue(
if (pass) return thisValue;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalObject, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const expected_fmt = expected.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalObject);
const expected_fmt = expected.toJestPrettyFormat(globalObject);
if (not) {
const received_fmt = value.toFmt(&formatter);
const received_fmt = value.toJestPrettyFormat(globalObject);
const expected_line = "Expected to not contain: <green>{any}<r>\nReceived: <red>{any}<r>\n";
const fmt = "\n\n" ++ expected_line;
return this.throw(globalObject, comptime getSignature("toContainValue", "<green>expected<r>", true), fmt, .{ expected_fmt, received_fmt });

View File

@@ -45,12 +45,10 @@ pub fn toContainValues(
if (pass) return thisValue;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalObject, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const expected_fmt = expected.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalObject);
const expected_fmt = expected.toJestPrettyFormat(globalObject);
if (not) {
const received_fmt = value.toFmt(&formatter);
const received_fmt = value.toJestPrettyFormat(globalObject);
const expected_line = "Expected to not contain: <green>{any}<r>\nReceived: <red>{any}<r>\n";
const fmt = "\n\n" ++ expected_line;
return this.throw(globalObject, comptime getSignature("toContainValues", "<green>expected<r>", true), fmt, .{ expected_fmt, received_fmt });

View File

@@ -34,10 +34,8 @@ pub fn toEndWith(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFra
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const expected_fmt = expected.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
const expected_fmt = expected.toJestPrettyFormat(globalThis);
if (not) {
const expected_line = "Expected to not end with: <green>{any}<r>\n";

View File

@@ -63,10 +63,8 @@ pub fn toEqualIgnoringWhitespace(this: *Expect, globalThis: *JSGlobalObject, cal
if (pass) return .js_undefined;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const expected_fmt = expected.toFmt(&formatter);
const value_fmt = value.toFmt(&formatter);
const expected_fmt = expected.toJestPrettyFormat(globalThis);
const value_fmt = value.toJestPrettyFormat(globalThis);
if (not) {
const signature = comptime getSignature("toEqualIgnoringWhitespace", "<green>expected<r>", true);

View File

@@ -13,9 +13,7 @@ pub fn toHaveBeenCalled(this: *Expect, globalThis: *JSGlobalObject, callframe: *
const calls = try bun.cpp.JSMockFunction__getCalls(globalThis, value);
this.incrementExpectCallCounter();
if (!calls.jsType().isArray()) {
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
return globalThis.throw("Expected value must be a mock function: {any}", .{value.toFmt(&formatter)});
return globalThis.throw("Expected value must be a mock function: {any}", .{value.toJestPrettyFormat(globalThis)});
}
const calls_length = try calls.getLength(globalThis);

View File

@@ -9,9 +9,7 @@ pub fn toHaveBeenCalledOnce(this: *Expect, globalThis: *JSGlobalObject, callfram
const calls = try bun.cpp.JSMockFunction__getCalls(globalThis, value);
if (!calls.jsType().isArray()) {
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
return globalThis.throw("Expected value must be a mock function: {any}", .{value.toFmt(&formatter)});
return globalThis.throw("Expected value must be a mock function: {any}", .{value.toJestPrettyFormat(globalThis)});
}
const calls_length = try calls.getLength(globalThis);

View File

@@ -11,9 +11,7 @@ pub fn toHaveBeenCalledTimes(this: *Expect, globalThis: *JSGlobalObject, callfra
const calls = try bun.cpp.JSMockFunction__getCalls(globalThis, value);
if (!calls.jsType().isArray()) {
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
return globalThis.throw("Expected value must be a mock function: {any}", .{value.toFmt(&formatter)});
return globalThis.throw("Expected value must be a mock function: {any}", .{value.toJestPrettyFormat(globalThis)});
}
if (arguments.len < 1 or !arguments[0].isUInt32AsAnyInt()) {

View File

@@ -10,9 +10,7 @@ pub fn toHaveBeenCalledWith(this: *Expect, globalThis: *JSGlobalObject, callfram
const calls = try bun.cpp.JSMockFunction__getCalls(globalThis, value);
if (!calls.jsType().isArray()) {
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
return this.throw(globalThis, comptime getSignature("toHaveBeenCalledWith", "<green>...expected<r>", false), "\n\nMatcher error: <red>received<r> value must be a mock function\nReceived: {any}", .{value.toFmt(&formatter)});
return this.throw(globalThis, comptime getSignature("toHaveBeenCalledWith", "<green>...expected<r>", false), "\n\nMatcher error: <red>received<r> value must be a mock function\nReceived: {any}", .{value.toJestPrettyFormat(globalThis)});
}
var pass = false;
@@ -51,8 +49,6 @@ pub fn toHaveBeenCalledWith(this: *Expect, globalThis: *JSGlobalObject, callfram
}
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const expected_args_js_array = try JSValue.createEmptyArray(globalThis, arguments.len);
for (arguments, 0..) |arg, i| {
@@ -63,14 +59,14 @@ pub fn toHaveBeenCalledWith(this: *Expect, globalThis: *JSGlobalObject, callfram
if (this.flags.not) {
const signature = comptime getSignature("toHaveBeenCalledWith", "<green>...expected<r>", true);
return this.throw(globalThis, signature, "\n\nExpected mock function not to have been called with: <green>{any}<r>\nBut it was.", .{
expected_args_js_array.toFmt(&formatter),
expected_args_js_array.toJestPrettyFormat(globalThis),
});
}
const signature = comptime getSignature("toHaveBeenCalledWith", "<green>...expected<r>", false);
if (calls_count == 0) {
return this.throw(globalThis, signature, "\n\nExpected: <green>{any}<r>\nBut it was not called.", .{
expected_args_js_array.toFmt(&formatter),
expected_args_js_array.toJestPrettyFormat(globalThis),
});
}
@@ -90,7 +86,6 @@ pub fn toHaveBeenCalledWith(this: *Expect, globalThis: *JSGlobalObject, callfram
const list_formatter = mock.AllCallsWithArgsFormatter{
.globalThis = globalThis,
.calls = calls,
.formatter = &formatter,
};
const fmt =
@@ -104,7 +99,7 @@ pub fn toHaveBeenCalledWith(this: *Expect, globalThis: *JSGlobalObject, callfram
switch (Output.enable_ansi_colors) {
inline else => |colors| {
return this.throw(globalThis, signature, Output.prettyFmt("\n\n" ++ fmt ++ "\n", colors), .{
expected_args_js_array.toFmt(&formatter),
expected_args_js_array.toJestPrettyFormat(globalThis),
list_formatter,
calls_count,
});

View File

@@ -10,9 +10,7 @@ pub fn toHaveBeenLastCalledWith(this: *Expect, globalThis: *JSGlobalObject, call
const calls = try bun.cpp.JSMockFunction__getCalls(globalThis, value);
if (!calls.jsType().isArray()) {
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
return this.throw(globalThis, comptime getSignature("toHaveBeenLastCalledWith", "<green>...expected<r>", false), "\n\nMatcher error: <red>received<r> value must be a mock function\nReceived: {any}", .{value.toFmt(&formatter)});
return this.throw(globalThis, comptime getSignature("toHaveBeenLastCalledWith", "<green>...expected<r>", false), "\n\nMatcher error: <red>received<r> value must be a mock function\nReceived: {any}", .{value.toJestPrettyFormat(globalThis)});
}
const totalCalls: u32 = @truncate(try calls.getLength(globalThis));
@@ -24,9 +22,7 @@ pub fn toHaveBeenLastCalledWith(this: *Expect, globalThis: *JSGlobalObject, call
lastCallValue = try calls.getIndex(globalThis, totalCalls - 1);
if (!lastCallValue.jsType().isArray()) {
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
return globalThis.throw("Expected value must be a mock function with calls: {any}", .{value.toFmt(&formatter)});
return globalThis.throw("Expected value must be a mock function with calls: {any}", .{value.toJestPrettyFormat(globalThis)});
}
if (try lastCallValue.getLength(globalThis) != arguments.len) {
@@ -47,8 +43,6 @@ pub fn toHaveBeenLastCalledWith(this: *Expect, globalThis: *JSGlobalObject, call
}
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const expected_args_js_array = try JSValue.createEmptyArray(globalThis, arguments.len);
for (arguments, 0..) |arg, i| {
@@ -59,14 +53,14 @@ pub fn toHaveBeenLastCalledWith(this: *Expect, globalThis: *JSGlobalObject, call
if (this.flags.not) {
const signature = comptime getSignature("toHaveBeenLastCalledWith", "<green>...expected<r>", true);
return this.throw(globalThis, signature, "\n\nExpected last call not to be with: <green>{any}<r>\nBut it was.", .{
expected_args_js_array.toFmt(&formatter),
expected_args_js_array.toJestPrettyFormat(globalThis),
});
}
const signature = comptime getSignature("toHaveBeenLastCalledWith", "<green>...expected<r>", false);
if (totalCalls == 0) {
return this.throw(globalThis, signature, "\n\nExpected: <green>{any}<r>\nBut it was not called.", .{
expected_args_js_array.toFmt(&formatter),
expected_args_js_array.toJestPrettyFormat(globalThis),
});
}

View File

@@ -10,9 +10,7 @@ pub fn toHaveBeenNthCalledWith(this: *Expect, globalThis: *JSGlobalObject, callf
const calls = try bun.cpp.JSMockFunction__getCalls(globalThis, value);
if (!calls.jsType().isArray()) {
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
return this.throw(globalThis, comptime getSignature("toHaveBeenNthCalledWith", "<green>n<r>, <green>...expected<r>", false), "\n\nMatcher error: <red>received<r> value must be a mock function\nReceived: {any}", .{value.toFmt(&formatter)});
return this.throw(globalThis, comptime getSignature("toHaveBeenNthCalledWith", "<green>n<r>, <green>...expected<r>", false), "\n\nMatcher error: <red>received<r> value must be a mock function\nReceived: {any}", .{value.toJestPrettyFormat(globalThis)});
}
if (arguments.len == 0 or !arguments[0].isAnyInt()) {
@@ -55,8 +53,6 @@ pub fn toHaveBeenNthCalledWith(this: *Expect, globalThis: *JSGlobalObject, callf
}
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const expected_args_slice = arguments[1..];
const expected_args_js_array = try JSValue.createEmptyArray(globalThis, expected_args_slice.len);
@@ -69,7 +65,7 @@ pub fn toHaveBeenNthCalledWith(this: *Expect, globalThis: *JSGlobalObject, callf
const signature = comptime getSignature("toHaveBeenNthCalledWith", "<green>n<r>, <green>...expected<r>", true);
return this.throw(globalThis, signature, "\n\nExpected call #{d} not to be with: <green>{any}<r>\nBut it was.", .{
nthCallNum,
expected_args_js_array.toFmt(&formatter),
expected_args_js_array.toJestPrettyFormat(globalThis),
});
}
const signature = comptime getSignature("toHaveBeenNthCalledWith", "<green>n<r>, <green>...expected<r>", false);

View File

@@ -11,9 +11,7 @@ pub fn toHaveLastReturnedWith(this: *Expect, globalThis: *JSGlobalObject, callfr
const returns = try bun.cpp.JSMockFunction__getReturns(globalThis, value);
if (!returns.jsType().isArray()) {
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
return globalThis.throw("Expected value must be a mock function: {any}", .{value.toFmt(&formatter)});
return globalThis.throw("Expected value must be a mock function: {any}", .{value.toJestPrettyFormat(globalThis)});
}
const calls_count = @as(u32, @intCast(try returns.getLength(globalThis)));
@@ -50,13 +48,11 @@ pub fn toHaveLastReturnedWith(this: *Expect, globalThis: *JSGlobalObject, callfr
}
// Handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const signature = comptime getSignature("toHaveBeenLastReturnedWith", "<green>expected<r>", false);
if (this.flags.not) {
return this.throw(globalThis, comptime getSignature("toHaveBeenLastReturnedWith", "<green>expected<r>", true), "\n\n" ++ "Expected mock function not to have last returned: <green>{any}<r>\n" ++ "But it did.\n", .{expected.toFmt(&formatter)});
return this.throw(globalThis, comptime getSignature("toHaveBeenLastReturnedWith", "<green>expected<r>", true), "\n\n" ++ "Expected mock function not to have last returned: <green>{any}<r>\n" ++ "But it did.\n", .{expected.toJestPrettyFormat(globalThis)});
}
if (calls_count == 0) {
@@ -64,7 +60,7 @@ pub fn toHaveLastReturnedWith(this: *Expect, globalThis: *JSGlobalObject, callfr
}
if (last_call_threw) {
return this.throw(globalThis, signature, "\n\n" ++ "The last call threw an error: <red>{any}<r>\n", .{last_error_value.toFmt(&formatter)});
return this.throw(globalThis, signature, "\n\n" ++ "The last call threw an error: <red>{any}<r>\n", .{last_error_value.toJestPrettyFormat(globalThis)});
}
// Diff if possible
@@ -73,7 +69,7 @@ pub fn toHaveLastReturnedWith(this: *Expect, globalThis: *JSGlobalObject, callfr
return this.throw(globalThis, signature, "\n\n{any}\n", .{diff_format});
}
return this.throw(globalThis, signature, "\n\nExpected: <green>{any}<r>\nReceived: <red>{any}<r>", .{ expected.toFmt(&formatter), last_return_value.toFmt(&formatter) });
return this.throw(globalThis, signature, "\n\nExpected: <green>{any}<r>\nReceived: <red>{any}<r>", .{ expected.toJestPrettyFormat(globalThis), last_return_value.toJestPrettyFormat(globalThis) });
}
const bun = @import("bun");

View File

@@ -19,9 +19,7 @@ pub fn toHaveNthReturnedWith(this: *Expect, globalThis: *JSGlobalObject, callfra
this.incrementExpectCallCounter();
const returns = try bun.cpp.JSMockFunction__getReturns(globalThis, value);
if (!returns.jsType().isArray()) {
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
return globalThis.throw("Expected value must be a mock function: {any}", .{value.toFmt(&formatter)});
return globalThis.throw("Expected value must be a mock function: {any}", .{value.toJestPrettyFormat(globalThis)});
}
const calls_count = @as(u32, @intCast(try returns.getLength(globalThis)));
@@ -59,13 +57,11 @@ pub fn toHaveNthReturnedWith(this: *Expect, globalThis: *JSGlobalObject, callfra
}
// Handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const signature = comptime getSignature("toHaveNthReturnedWith", "<green>n<r>, <green>expected<r>", false);
if (this.flags.not) {
return this.throw(globalThis, comptime getSignature("toHaveNthReturnedWith", "<green>n<r>, <green>expected<r>", true), "\n\n" ++ "Expected mock function not to have returned on call {d}: <green>{any}<r>\n" ++ "But it did.\n", .{ n, expected.toFmt(&formatter) });
return this.throw(globalThis, comptime getSignature("toHaveNthReturnedWith", "<green>n<r>, <green>expected<r>", true), "\n\n" ++ "Expected mock function not to have returned on call {d}: <green>{any}<r>\n" ++ "But it did.\n", .{ n, expected.toJestPrettyFormat(globalThis) });
}
if (!nth_call_exists) {
@@ -73,7 +69,7 @@ pub fn toHaveNthReturnedWith(this: *Expect, globalThis: *JSGlobalObject, callfra
}
if (nth_call_threw) {
return this.throw(globalThis, signature, "\n\n" ++ "Call {d} threw an error: <red>{any}<r>\n", .{ n, nth_error_value.toFmt(&formatter) });
return this.throw(globalThis, signature, "\n\n" ++ "Call {d} threw an error: <red>{any}<r>\n", .{ n, nth_error_value.toJestPrettyFormat(globalThis) });
}
// Diff if possible
@@ -82,7 +78,7 @@ pub fn toHaveNthReturnedWith(this: *Expect, globalThis: *JSGlobalObject, callfra
return this.throw(globalThis, signature, "\n\nCall {d}:\n{any}\n", .{ n, diff_format });
}
return this.throw(globalThis, signature, "\n\nCall {d}:\nExpected: <green>{any}<r>\nReceived: <red>{any}<r>", .{ n, expected.toFmt(&formatter), nth_return_value.toFmt(&formatter) });
return this.throw(globalThis, signature, "\n\nCall {d}:\nExpected: <green>{any}<r>\nReceived: <red>{any}<r>", .{ n, expected.toJestPrettyFormat(globalThis), nth_return_value.toJestPrettyFormat(globalThis) });
}
const bun = @import("bun");

View File

@@ -42,23 +42,21 @@ pub fn toHaveProperty(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Ca
if (pass) return .js_undefined;
// handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
if (not) {
if (expected_property != null) {
const signature = comptime getSignature("toHaveProperty", "<green>path<r><d>, <r><green>value<r>", true);
if (received_property != .zero) {
return this.throw(globalThis, signature, "\n\nExpected path: <green>{any}<r>\n\nExpected value: not <green>{any}<r>\n", .{
expected_property_path.toFmt(&formatter),
expected_property.?.toFmt(&formatter),
expected_property_path.toJestPrettyFormat(globalThis),
expected_property.?.toJestPrettyFormat(globalThis),
});
}
}
const signature = comptime getSignature("toHaveProperty", "<green>path<r>", true);
return this.throw(globalThis, signature, "\n\nExpected path: not <green>{any}<r>\n\nReceived value: <red>{any}<r>\n", .{
expected_property_path.toFmt(&formatter),
received_property.toFmt(&formatter),
expected_property_path.toJestPrettyFormat(globalThis),
received_property.toJestPrettyFormat(globalThis),
});
}
@@ -78,13 +76,13 @@ pub fn toHaveProperty(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Ca
const fmt = "\n\nExpected path: <green>{any}<r>\n\nExpected value: <green>{any}<r>\n\n" ++
"Unable to find property\n";
return this.throw(globalThis, signature, fmt, .{
expected_property_path.toFmt(&formatter),
expected_property.?.toFmt(&formatter),
expected_property_path.toJestPrettyFormat(globalThis),
expected_property.?.toJestPrettyFormat(globalThis),
});
}
const signature = comptime getSignature("toHaveProperty", "<green>path<r>", false);
return this.throw(globalThis, signature, "\n\nExpected path: <green>{any}<r>\n\nUnable to find property\n", .{expected_property_path.toFmt(&formatter)});
return this.throw(globalThis, signature, "\n\nExpected path: <green>{any}<r>\n\nUnable to find property\n", .{expected_property_path.toJestPrettyFormat(globalThis)});
}
const DiffFormatter = @import("../diff_format.zig").DiffFormatter;

View File

@@ -11,9 +11,7 @@ pub fn toHaveReturnedWith(this: *Expect, globalThis: *JSGlobalObject, callframe:
const returns = try bun.cpp.JSMockFunction__getReturns(globalThis, value);
if (!returns.jsType().isArray()) {
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
return globalThis.throw("Expected value must be a mock function: {any}", .{value.toFmt(&formatter)});
return globalThis.throw("Expected value must be a mock function: {any}", .{value.toJestPrettyFormat(globalThis)});
}
const calls_count = @as(u32, @intCast(try returns.getLength(globalThis)));
@@ -56,14 +54,12 @@ pub fn toHaveReturnedWith(this: *Expect, globalThis: *JSGlobalObject, callframe:
}
// Handle failure
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const signature = comptime getSignature("toHaveReturnedWith", "<green>expected<r>", false);
if (this.flags.not) {
const not_signature = comptime getSignature("toHaveReturnedWith", "<green>expected<r>", true);
return this.throw(globalThis, not_signature, "\n\n" ++ "Expected mock function not to have returned: <green>{any}<r>\n", .{expected.toFmt(&formatter)});
return this.throw(globalThis, not_signature, "\n\n" ++ "Expected mock function not to have returned: <green>{any}<r>\n", .{expected.toJestPrettyFormat(globalThis)});
}
// No match was found.
@@ -83,8 +79,8 @@ pub fn toHaveReturnedWith(this: *Expect, globalThis: *JSGlobalObject, callframe:
}
return this.throw(globalThis, signature, "\n\nExpected: <green>{any}<r>\nReceived: <red>{any}<r>", .{
expected.toFmt(&formatter),
received.toFmt(&formatter),
expected.toJestPrettyFormat(globalThis),
received.toJestPrettyFormat(globalThis),
});
}
@@ -93,7 +89,6 @@ pub fn toHaveReturnedWith(this: *Expect, globalThis: *JSGlobalObject, callframe:
const list_formatter = mock.AllCallsFormatter{
.globalThis = globalThis,
.returns = returns,
.formatter = &formatter,
};
const fmt =
\\Some calls errored:
@@ -109,7 +104,7 @@ pub fn toHaveReturnedWith(this: *Expect, globalThis: *JSGlobalObject, callframe:
switch (Output.enable_ansi_colors) {
inline else => |colors| {
return this.throw(globalThis, signature, Output.prettyFmt("\n\n" ++ fmt ++ "\n", colors), .{
expected.toFmt(&formatter),
expected.toJestPrettyFormat(globalThis),
list_formatter,
successful_returns_count,
calls_count,
@@ -121,7 +116,6 @@ pub fn toHaveReturnedWith(this: *Expect, globalThis: *JSGlobalObject, callframe:
const list_formatter = mock.SuccessfulReturnsFormatter{
.globalThis = globalThis,
.successful_returns = &successful_returns,
.formatter = &formatter,
};
const fmt =
\\ <green>Expected<r>: {any}
@@ -134,7 +128,7 @@ pub fn toHaveReturnedWith(this: *Expect, globalThis: *JSGlobalObject, callframe:
switch (Output.enable_ansi_colors) {
inline else => |colors| {
return this.throw(globalThis, signature, Output.prettyFmt("\n\n" ++ fmt ++ "\n", colors), .{
expected.toFmt(&formatter),
expected.toJestPrettyFormat(globalThis),
list_formatter,
successful_returns_count,
});

View File

@@ -34,10 +34,8 @@ pub fn toInclude(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFra
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const expected_fmt = expected.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
const expected_fmt = expected.toJestPrettyFormat(globalThis);
if (not) {
const expected_line = "Expected to not include: <green>{any}<r>\n";

View File

@@ -59,11 +59,9 @@ pub fn toIncludeRepeated(this: *Expect, globalThis: *JSGlobalObject, callFrame:
if (not) pass = !pass;
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const expect_string_fmt = expect_string.toFmt(&formatter);
const substring_fmt = substring.toFmt(&formatter);
const times_fmt = count.toFmt(&formatter);
const expect_string_fmt = expect_string.toJestPrettyFormat(globalThis);
const substring_fmt = substring.toJestPrettyFormat(globalThis);
const times_fmt = count.toJestPrettyFormat(globalThis);
const received_line = "Received: <red>{any}<r>\n";

View File

@@ -13,19 +13,16 @@ pub fn toMatch(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame
this.incrementExpectCallCounter();
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const expected_value = arguments[0];
if (!expected_value.isString() and !expected_value.isRegExp()) {
return globalThis.throw("Expected value must be a string or regular expression: {any}", .{expected_value.toFmt(&formatter)});
return globalThis.throw("Expected value must be a string or regular expression: {any}", .{expected_value.toJestPrettyFormat(globalThis)});
}
expected_value.ensureStillAlive();
const value: JSValue = try this.getValue(globalThis, thisValue, "toMatch", "<green>expected<r>");
if (!value.isString()) {
return globalThis.throw("Received value must be a string: {any}", .{value.toFmt(&formatter)});
return globalThis.throw("Received value must be a string: {any}", .{value.toJestPrettyFormat(globalThis)});
}
const not = this.flags.not;
@@ -42,8 +39,8 @@ pub fn toMatch(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame
if (pass) return .js_undefined;
// handle failure
const expected_fmt = expected_value.toFmt(&formatter);
const value_fmt = value.toFmt(&formatter);
const expected_fmt = expected_value.toJestPrettyFormat(globalThis);
const value_fmt = value.toJestPrettyFormat(globalThis);
if (not) {
const expected_line = "Expected substring or pattern: not <green>{any}<r>\n";

View File

@@ -34,19 +34,16 @@ pub fn toSatisfy(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFra
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
if (not) {
const signature = comptime getSignature("toSatisfy", "<green>expected<r>", true);
return this.throw(globalThis, signature, "\n\nExpected: not <green>{any}<r>\n", .{predicate.toFmt(&formatter)});
return this.throw(globalThis, signature, "\n\nExpected: not <green>{any}<r>\n", .{predicate.toJestPrettyFormat(globalThis)});
}
const signature = comptime getSignature("toSatisfy", "<green>expected<r>", false);
return this.throw(globalThis, signature, "\n\nExpected: <green>{any}<r>\nReceived: <red>{any}<r>\n", .{
predicate.toFmt(&formatter),
value.toFmt(&formatter),
predicate.toJestPrettyFormat(globalThis),
value.toJestPrettyFormat(globalThis),
});
}

View File

@@ -34,10 +34,8 @@ pub fn toStartWith(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallF
if (pass) return .js_undefined;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const value_fmt = value.toFmt(&formatter);
const expected_fmt = expected.toFmt(&formatter);
const value_fmt = value.toJestPrettyFormat(globalThis);
const expected_fmt = expected.toJestPrettyFormat(globalThis);
if (not) {
const expected_line = "Expected to not start with: <green>{any}<r>\n";

View File

@@ -42,8 +42,6 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame
if (!did_throw) return .js_undefined;
const result: JSValue = result_.?;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
if (expected_value == .zero or expected_value.isUndefined()) {
const signature_no_args = comptime getSignature("toThrow", "", true);
@@ -52,14 +50,14 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame
const message: JSValue = try err.getTruthyComptime(globalThis, "message") orelse .js_undefined;
const fmt = signature_no_args ++ "\n\nError name: <red>{any}<r>\nError message: <red>{any}<r>\n";
return globalThis.throwPretty(fmt, .{
name.toFmt(&formatter),
message.toFmt(&formatter),
name.toJestPrettyFormat(globalThis),
message.toJestPrettyFormat(globalThis),
});
}
// non error thrown
const fmt = signature_no_args ++ "\n\nThrown value: <red>{any}<r>\n";
return globalThis.throwPretty(fmt, .{result.toFmt(&formatter)});
return globalThis.throwPretty(fmt, .{result.toJestPrettyFormat(globalThis)});
}
if (expected_value.isString()) {
@@ -80,8 +78,8 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame
}
return this.throw(globalThis, signature, "\n\nExpected substring: not <green>{any}<r>\nReceived message: <red>{any}<r>\n", .{
expected_value.toFmt(&formatter),
received_message.toFmt(&formatter),
expected_value.toJestPrettyFormat(globalThis),
received_message.toJestPrettyFormat(globalThis),
});
}
@@ -99,8 +97,8 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame
}
return this.throw(globalThis, signature, "\n\nExpected pattern: not <green>{any}<r>\nReceived message: <red>{any}<r>\n", .{
expected_value.toFmt(&formatter),
received_message.toFmt(&formatter),
expected_value.toJestPrettyFormat(globalThis),
received_message.toJestPrettyFormat(globalThis),
});
}
@@ -114,7 +112,7 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame
// no partial match for this case
if (!try expected_message.isSameValue(received_message, globalThis)) return .js_undefined;
return this.throw(globalThis, signature, "\n\nExpected message: not <green>{any}<r>\n", .{expected_message.toFmt(&formatter)});
return this.throw(globalThis, signature, "\n\nExpected message: not <green>{any}<r>\n", .{expected_message.toJestPrettyFormat(globalThis)});
}
if (!result.isInstanceOf(globalThis, expected_value)) return .js_undefined;
@@ -122,7 +120,7 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame
var expected_class = ZigString.Empty;
try expected_value.getClassName(globalThis, &expected_class);
const received_message: JSValue = (try result.fastGet(globalThis, .message)) orelse .js_undefined;
return this.throw(globalThis, signature, "\n\nExpected constructor: not <green>{s}<r>\n\nReceived message: <red>{any}<r>\n", .{ expected_class, received_message.toFmt(&formatter) });
return this.throw(globalThis, signature, "\n\nExpected constructor: not <green>{s}<r>\n\nReceived message: <red>{any}<r>\n", .{ expected_class, received_message.toJestPrettyFormat(globalThis) });
}
if (did_throw) {
@@ -150,19 +148,17 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame
}
// error: message from received error does not match expected string
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const signature = comptime getSignature("toThrow", "<green>expected<r>", false);
if (_received_message) |received_message| {
const expected_value_fmt = expected_value.toFmt(&formatter);
const received_message_fmt = received_message.toFmt(&formatter);
const expected_value_fmt = expected_value.toJestPrettyFormat(globalThis);
const received_message_fmt = received_message.toJestPrettyFormat(globalThis);
return this.throw(globalThis, signature, "\n\n" ++ "Expected substring: <green>{any}<r>\nReceived message: <red>{any}<r>\n", .{ expected_value_fmt, received_message_fmt });
}
const expected_fmt = expected_value.toFmt(&formatter);
const received_fmt = result.toFmt(&formatter);
const expected_fmt = expected_value.toJestPrettyFormat(globalThis);
const received_fmt = result.toJestPrettyFormat(globalThis);
return this.throw(globalThis, signature, "\n\n" ++ "Expected substring: <green>{any}<r>\nReceived value: <red>{any}<r>", .{ expected_fmt, received_fmt });
}
@@ -176,19 +172,17 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame
}
// error: message from received error does not match expected pattern
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
if (_received_message) |received_message| {
const expected_value_fmt = expected_value.toFmt(&formatter);
const received_message_fmt = received_message.toFmt(&formatter);
const expected_value_fmt = expected_value.toJestPrettyFormat(globalThis);
const received_message_fmt = received_message.toJestPrettyFormat(globalThis);
const signature = comptime getSignature("toThrow", "<green>expected<r>", false);
return this.throw(globalThis, signature, "\n\n" ++ "Expected pattern: <green>{any}<r>\nReceived message: <red>{any}<r>\n", .{ expected_value_fmt, received_message_fmt });
}
const expected_fmt = expected_value.toFmt(&formatter);
const received_fmt = result.toFmt(&formatter);
const expected_fmt = expected_value.toJestPrettyFormat(globalThis);
const received_fmt = result.toJestPrettyFormat(globalThis);
const signature = comptime getSignature("toThrow", "<green>expected<r>", false);
return this.throw(globalThis, signature, "\n\n" ++ "Expected pattern: <green>{any}<r>\nReceived value: <red>{any}<r>", .{ expected_fmt, received_fmt });
}
@@ -205,10 +199,8 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame
return .js_undefined;
}
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received_fmt = result.toFmt(&formatter);
const expected_fmt = expected_value.toFmt(&formatter);
const received_fmt = result.toJestPrettyFormat(globalThis);
const expected_fmt = expected_value.toJestPrettyFormat(globalThis);
return this.throw(globalThis, signature, "\n\nExpected value: <green>{any}<r>\nReceived value: <red>{any}<r>\n", .{ expected_fmt, received_fmt });
}
@@ -223,25 +215,21 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame
}
// error: message from received error does not match expected error message.
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
if (_received_message) |received_message| {
const expected_fmt = expected_message.toFmt(&formatter);
const received_fmt = received_message.toFmt(&formatter);
const expected_fmt = expected_message.toJestPrettyFormat(globalThis);
const received_fmt = received_message.toJestPrettyFormat(globalThis);
return this.throw(globalThis, signature, "\n\nExpected message: <green>{any}<r>\nReceived message: <red>{any}<r>\n", .{ expected_fmt, received_fmt });
}
const expected_fmt = expected_message.toFmt(&formatter);
const received_fmt = result.toFmt(&formatter);
const expected_fmt = expected_message.toJestPrettyFormat(globalThis);
const received_fmt = result.toJestPrettyFormat(globalThis);
return this.throw(globalThis, signature, "\n\nExpected message: <green>{any}<r>\nReceived value: <red>{any}<r>\n", .{ expected_fmt, received_fmt });
}
if (result.isInstanceOf(globalThis, expected_value)) return .js_undefined;
// error: received error not instance of received error constructor
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
var expected_class = ZigString.Empty;
var received_class = ZigString.Empty;
try expected_value.getClassName(globalThis, &expected_class);
@@ -251,7 +239,7 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame
if (_received_message) |received_message| {
const message_fmt = fmt ++ "Received message: <red>{any}<r>\n";
const received_message_fmt = received_message.toFmt(&formatter);
const received_message_fmt = received_message.toJestPrettyFormat(globalThis);
return globalThis.throwPretty(message_fmt, .{
expected_class,
@@ -260,7 +248,7 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame
});
}
const received_fmt = result.toFmt(&formatter);
const received_fmt = result.toJestPrettyFormat(globalThis);
const value_fmt = fmt ++ "Received value: <red>{any}<r>\n";
return globalThis.throwPretty(value_fmt, .{
@@ -272,36 +260,34 @@ pub fn toThrow(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallFrame
// did not throw
const result = return_value_from_function;
var formatter = jsc.ConsoleObject.Formatter{ .globalThis = globalThis, .quote_strings = true };
defer formatter.deinit();
const received_line = "Received function did not throw\nReceived value: <red>{any}<r>\n";
if (expected_value == .zero or expected_value.isUndefined()) {
const signature = comptime getSignature("toThrow", "", false);
return this.throw(globalThis, signature, "\n\n" ++ received_line, .{result.toFmt(&formatter)});
return this.throw(globalThis, signature, "\n\n" ++ received_line, .{result.toJestPrettyFormat(globalThis)});
}
const signature = comptime getSignature("toThrow", "<green>expected<r>", false);
if (expected_value.isString()) {
const expected_fmt = "\n\nExpected substring: <green>{any}<r>\n\n" ++ received_line;
return this.throw(globalThis, signature, expected_fmt, .{ expected_value.toFmt(&formatter), result.toFmt(&formatter) });
return this.throw(globalThis, signature, expected_fmt, .{ expected_value.toJestPrettyFormat(globalThis), result.toJestPrettyFormat(globalThis) });
}
if (expected_value.isRegExp()) {
const expected_fmt = "\n\nExpected pattern: <green>{any}<r>\n\n" ++ received_line;
return this.throw(globalThis, signature, expected_fmt, .{ expected_value.toFmt(&formatter), result.toFmt(&formatter) });
return this.throw(globalThis, signature, expected_fmt, .{ expected_value.toJestPrettyFormat(globalThis), result.toJestPrettyFormat(globalThis) });
}
if (try expected_value.fastGet(globalThis, .message)) |expected_message| {
const expected_fmt = "\n\nExpected message: <green>{any}<r>\n\n" ++ received_line;
return this.throw(globalThis, signature, expected_fmt, .{ expected_message.toFmt(&formatter), result.toFmt(&formatter) });
return this.throw(globalThis, signature, expected_fmt, .{ expected_message.toJestPrettyFormat(globalThis), result.toJestPrettyFormat(globalThis) });
}
const expected_fmt = "\n\nExpected constructor: <green>{s}<r>\n\n" ++ received_line;
var expected_class = ZigString.Empty;
try expected_value.getClassName(globalThis, &expected_class);
return this.throw(globalThis, signature, expected_fmt, .{ expected_class, result.toFmt(&formatter) });
return this.throw(globalThis, signature, expected_fmt, .{ expected_class, result.toJestPrettyFormat(globalThis) });
}
const bun = @import("bun");