Skip to content

Commit 001364b

Browse files
committed
test: inject platform to the serveCDP app
1 parent 6edace8 commit 001364b

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
@@ -264,18 +264,12 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
264264
}
265265

266266
pub fn pumpMessageLoop(self: *const Self) bool {
267-
if (comptime builtin.is_test) {
268-
if (self.platform == null) return false;
269-
}
270-
// assume it's not-null in non-test.
267+
// assume it's not-null.
271268
return self.platform.?.inner.pumpMessageLoop(self.isolate, false);
272269
}
273270

274271
pub fn runIdleTasks(self: *const Self) void {
275-
if (comptime builtin.is_test) {
276-
if (self.platform == null) return;
277-
}
278-
// assume it's not-null in non-test.
272+
// assume it's not-null.
279273
return self.platform.?.inner.runIdleTasks(self.isolate, 1);
280274
}
281275

0 commit comments

Comments
 (0)