aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-06-22 06:43:13 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-06-22 06:56:47 -0700
commite3a00268eb05ec71edd4826d72c61a928a050f6d (patch)
tree15b30338a9aac7b1b844446d33f32ecdee2bfb06
parent527eb40a2c114d5a361ab5506a82c9b7701e03f7 (diff)
downloadbun-e3a00268eb05ec71edd4826d72c61a928a050f6d.tar.gz
bun-e3a00268eb05ec71edd4826d72c61a928a050f6d.tar.zst
bun-e3a00268eb05ec71edd4826d72c61a928a050f6d.zip
use JSValue for `bun test`
-rw-r--r--src/javascript/jsc/test/jest.zig32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/javascript/jsc/test/jest.zig b/src/javascript/jsc/test/jest.zig
index 52bed96db..5ca581d53 100644
--- a/src/javascript/jsc/test/jest.zig
+++ b/src/javascript/jsc/test/jest.zig
@@ -195,7 +195,7 @@ pub const Jest = struct {
pub const Expect = struct {
test_id: TestRunner.Test.ID,
scope: *DescribeScope,
- value: js.JSValueRef,
+ value: JSValue,
op: Op.Set = Op.Set.init(.{}),
pub const Op = enum(u3) {
@@ -208,7 +208,7 @@ pub const Expect = struct {
pub fn finalize(
this: *Expect,
) void {
- js.JSValueUnprotect(VirtualMachine.vm.global.ref(), this.value);
+ this.value.unprotect();
VirtualMachine.vm.allocator.destroy(this);
}
@@ -367,9 +367,15 @@ pub const Expect = struct {
}
this.scope.tests.items[this.test_id].counter.actual += 1;
const left = JSValue.fromRef(arguments[0]);
- const right = JSValue.fromRef(this.value);
+ left.ensureStillAlive();
+ const right = this.value;
+ right.ensureStillAlive();
+ const eql = left.isSameValue(right, ctx.ptr());
+ if (comptime Environment.allow_assert) {
+ std.debug.assert(eql == JSC.C.JSValueIsStrictEqual(ctx, left.asObjectRef(), right.asObjectRef()));
+ }
- if (!left.isSameValue(right, ctx.ptr())) {
+ if (!eql) {
if (comptime Environment.allow_assert) {
if (left.isString() and right.isString()) {
var left_slice = left.toSlice(ctx, getAllocator(ctx));
@@ -383,6 +389,10 @@ pub const Expect = struct {
var lhs_formatter: JSC.ZigConsoleClient.Formatter = JSC.ZigConsoleClient.Formatter{ .globalThis = ctx.ptr() };
var rhs_formatter: JSC.ZigConsoleClient.Formatter = JSC.ZigConsoleClient.Formatter{ .globalThis = ctx.ptr() };
+ if (comptime Environment.allow_assert) {
+ Output.prettyErrorln("\nJSType: {s}\nJSType: {s}\n\n", .{ @tagName(left.jsType()), @tagName(right.jsType()) });
+ }
+
JSC.JSError(
getAllocator(ctx),
"Expected: {}\n\tReceived: {}",
@@ -421,7 +431,7 @@ pub const Expect = struct {
this.scope.tests.items[this.test_id].counter.actual += 1;
const expected = JSC.JSValue.fromRef(arguments[0]).toU32();
- const actual = JSC.JSValue.fromRef(this.value).getLengthOfArray(ctx.ptr());
+ const actual = this.value.getLengthOfArray(ctx.ptr());
if (expected != actual) {
JSC.JSError(
getAllocator(ctx),
@@ -570,14 +580,14 @@ pub const ExpectPrototype = struct {
return js.JSValueMakeUndefined(ctx);
}
var expect_ = getAllocator(ctx).create(Expect) catch unreachable;
- if (JSC.JSValue.c(arguments[0]).isCell())
- js.JSValueProtect(ctx, arguments[0]);
+ const value = JSC.JSValue.c(arguments[0]);
+ value.protect();
expect_.* = .{
- .value = arguments[0],
+ .value = value,
.scope = DescribeScope.active,
.test_id = DescribeScope.active.current_test_id,
};
- expect_.value.?.value().ensureStillAlive();
+ expect_.value.ensureStillAlive();
return Expect.Class.make(ctx, expect_);
}
};
@@ -1012,10 +1022,6 @@ pub const DescribeScope = struct {
}
}
- pub const callAfterAll = notImplementedFn;
- pub const callAfterEach = notImplementedFn;
- pub const callBeforeAll = notImplementedFn;
-
pub fn createExpect(
_: *DescribeScope,
ctx: js.JSContextRef,