webapi: experimental (and useless, for now) ServiceWorker

This adds the shell for ServiceWorker, behind
`--experimental-features serviceworker`.

It's pretty useless as-is. We don't have the CacheStorage API (next) and don't
have the fetch interceptor (next next). But as-is, the change is quite big but
thankfully largely isolated.
This commit is contained in:
Karl Seguin committed 2026-09-16 17:49:07 +08:00
1 parent afbc8378b1
commit dc1ae129e3
27 files changed
+2063 -58

No files matched your search

+9 -1
View File
@@ -333,6 +333,7 @@ const HtmlRunnerOpts = struct {
.worker = true,
.iframe = true,
},
experimental_features: Config.ExperimentalFeatures = .{},
};
// Create a fresh page on `test_session` and return its root frame — for tests
@@ -365,6 +366,9 @@ pub fn htmlRunner(comptime path: []const u8, opts: HtmlRunnerOpts) !void {
.iframe = true,
};
test_session.experimental_features = opts.experimental_features;
defer test_session.experimental_features = .{};
const root = try std.fs.path.joinZ(arena_allocator, &.{ WEB_API_TEST_ROOT, path });
const stat = std.Io.Dir.cwd().statFile(io, root, .{}) catch |err| {
std.debug.print("Failed to stat file: '{s}'", .{root});
@@ -448,7 +452,11 @@ fn runWebApiTest(test_file: [:0]const u8, timeout_ms: u32) !void {
try_catch.init(&ls.local);
defer try_catch.deinit();
const js_val = ls.local.exec("testing.assertOk()", "testing.assertOk()") catch |err| {
const js_val = ls.local.exec(
// testing is undefined until testing.js is run
"typeof testing === 'undefined' ? false : testing.assertOk()",
"testing.assertOk()",
) catch |err| {
const caught = try_catch.caughtOrError(arena_allocator, err);
std.debug.print("{s}: test failure\nError: {f}\n", .{ test_file, caught });
return err;