Skip to content

Commit f8425fe

Browse files
authored
Merge pull request #1063 from lightpanda-io/remove_jsrunner
Remove JSRunner
2 parents 7802a1b + 17549d8 commit f8425fe

File tree

2 files changed

+1
-125
lines changed

2 files changed

+1
-125
lines changed

src/browser/page.zig

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,7 @@ pub const Page = struct {
347347
std.debug.assert(http_client.intercepted == 0);
348348

349349
const ms = ms_to_next_task orelse blk: {
350-
// TODO: when jsRunner is fully replaced with the
351-
// htmlRunner, we can remove the first part of this
352-
// condition. jsRunner calls `page.wait` far too
353-
// often to enforce this.
354-
if (wait_ms > 100 and wait_ms - ms_remaining < 100) {
350+
if (wait_ms - ms_remaining < 100) {
355351
// Look, we want to exit ASAP, but we don't want
356352
// to exit so fast that we've run none of the
357353
// background jobs.

src/testing.zig

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -363,126 +363,6 @@ fn isJsonValue(a: std.json.Value, b: std.json.Value) bool {
363363
}
364364

365365
pub const tracking_allocator = @import("root").tracking_allocator.allocator();
366-
pub const JsRunner = struct {
367-
const URL = @import("url.zig").URL;
368-
const Page = @import("browser/page.zig").Page;
369-
370-
page: *Page,
371-
browser: *Browser,
372-
allocator: Allocator,
373-
374-
fn init(alloc: Allocator, opts: RunnerOpts) !JsRunner {
375-
const browser = try alloc.create(Browser);
376-
errdefer alloc.destroy(browser);
377-
378-
browser.* = try Browser.init(test_app);
379-
errdefer browser.deinit();
380-
381-
var session = try browser.newSession();
382-
383-
var page = try session.createPage();
384-
385-
// a bit hacky, but since we aren't going through page.navigate, there's
386-
// some minimum setup we need to do
387-
page.url = try URL.parse(opts.url, null);
388-
try page.window.replaceLocation(.{
389-
.url = try page.url.toWebApi(page.arena),
390-
});
391-
392-
const html_doc = try parser.documentHTMLParseFromStr(opts.html);
393-
try page.setDocument(html_doc);
394-
page.mode = .{ .parsed = {} };
395-
396-
return .{
397-
.page = page,
398-
.browser = browser,
399-
.allocator = alloc,
400-
};
401-
}
402-
403-
pub fn deinit(self: *JsRunner) void {
404-
self.browser.deinit();
405-
self.allocator.destroy(self.browser);
406-
}
407-
408-
const RunOpts = struct {};
409-
pub const Case = std.meta.Tuple(&.{ []const u8, ?[]const u8 });
410-
pub fn testCases(self: *JsRunner, cases: []const Case, _: RunOpts) !void {
411-
const js_context = self.page.main_context;
412-
const arena = self.page.arena;
413-
414-
const start = try std.time.Instant.now();
415-
416-
for (cases, 0..) |case, i| {
417-
var try_catch: Env.TryCatch = undefined;
418-
try_catch.init(js_context);
419-
defer try_catch.deinit();
420-
421-
const value = js_context.exec(case.@"0", null) catch |err| {
422-
if (try try_catch.err(arena)) |msg| {
423-
std.debug.print("{s}\n\nCase: {d}\n{s}\n", .{ msg, i + 1, case.@"0" });
424-
}
425-
return err;
426-
};
427-
_ = self.page.session.wait(100);
428-
@import("root").js_runner_duration += std.time.Instant.since(try std.time.Instant.now(), start);
429-
430-
if (case.@"1") |expected| {
431-
const actual = try value.toString(arena);
432-
if (std.mem.eql(u8, expected, actual) == false) {
433-
std.debug.print("Expected:\n{s}\n\nGot:\n{s}\n\nCase: {d}\n{s}\n", .{ expected, actual, i + 1, case.@"0" });
434-
return error.UnexpectedResult;
435-
}
436-
}
437-
}
438-
}
439-
440-
pub fn exec(self: *JsRunner, src: []const u8, name: ?[]const u8, err_msg: *?[]const u8) !void {
441-
_ = try self.eval(src, name, err_msg);
442-
}
443-
444-
pub fn eval(self: *JsRunner, src: []const u8, name: ?[]const u8, err_msg: *?[]const u8) !Env.Value {
445-
const js_context = self.page.main_context;
446-
const arena = self.page.arena;
447-
448-
var try_catch: Env.TryCatch = undefined;
449-
try_catch.init(js_context);
450-
defer try_catch.deinit();
451-
452-
return js_context.exec(src, name) catch |err| {
453-
if (try try_catch.err(arena)) |msg| {
454-
err_msg.* = msg;
455-
std.debug.print("Error running script: {s}\n", .{msg});
456-
}
457-
return err;
458-
};
459-
}
460-
461-
pub fn dispatchDOMContentLoaded(self: *JsRunner) !void {
462-
const HTMLDocument = @import("browser/html/document.zig").HTMLDocument;
463-
const html_doc = self.page.window.document;
464-
try HTMLDocument.documentIsLoaded(html_doc, self.page);
465-
}
466-
};
467-
468-
const RunnerOpts = struct {
469-
url: []const u8 = "https://lightpanda.io/opensource-browser/",
470-
html: []const u8 =
471-
\\ <div id="content">
472-
\\ <a id="link" href="foo" class="ok">OK</a>
473-
\\ <p id="para-empty" class="ok empty">
474-
\\ <span id="para-empty-child"></span>
475-
\\ </p>
476-
\\ <p id="para"> And</p>
477-
\\ <!--comment-->
478-
\\ </div>
479-
\\
480-
,
481-
};
482-
483-
pub fn jsRunner(alloc: Allocator, opts: RunnerOpts) !JsRunner {
484-
return JsRunner.init(alloc, opts);
485-
}
486366

487367
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
488368
pub var test_app: *App = undefined;

0 commit comments

Comments
 (0)