Skip to content

Commit b78729f

Browse files
committed
test: inject platform to the serveCDP app
1 parent 44a76e5 commit b78729f

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

src/main.zig

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ test "tests:beforeAll" {
603603
log.opts.format = .logfmt;
604604

605605
test_wg.startMany(3);
606-
_ = try Platform.init();
606+
const platform = try Platform.init();
607607

608608
{
609609
const address = try std.net.Address.parseIp("127.0.0.1", 9582);
@@ -619,7 +619,7 @@ test "tests:beforeAll" {
619619

620620
{
621621
const address = try std.net.Address.parseIp("127.0.0.1", 9583);
622-
const thread = try std.Thread.spawn(.{}, serveCDP, .{address});
622+
const thread = try std.Thread.spawn(.{}, serveCDP, .{ address, &platform });
623623
thread.detach();
624624
}
625625

@@ -801,11 +801,12 @@ fn serveHTTPS(address: std.net.Address) !void {
801801
}
802802
}
803803

804-
fn serveCDP(address: std.net.Address) !void {
804+
fn serveCDP(address: std.net.Address, platform: *const Platform) !void {
805805
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
806806
var app = try App.init(gpa.allocator(), .{
807807
.run_mode = .serve,
808808
.tls_verify_host = false,
809+
.platform = platform,
809810
});
810811
defer app.deinit();
811812

src/runtime/js.zig

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,18 +274,12 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
274274
}
275275

276276
pub fn pumpMessageLoop(self: *const Self) bool {
277-
if (comptime builtin.is_test) {
278-
if (self.platform == null) return false;
279-
}
280-
// assume it's not-null in non-test.
277+
// assume it's not-null.
281278
return self.platform.?.inner.pumpMessageLoop(self.isolate, false);
282279
}
283280

284281
pub fn runIdleTasks(self: *const Self) void {
285-
if (comptime builtin.is_test) {
286-
if (self.platform == null) return;
287-
}
288-
// assume it's not-null in non-test.
282+
// assume it's not-null.
289283
return self.platform.?.inner.runIdleTasks(self.isolate, 1);
290284
}
291285

0 commit comments

Comments
 (0)