@@ -22,9 +22,8 @@ const Allocator = std.mem.Allocator;
2222
2323const log = @import ("log.zig" );
2424const App = @import ("app.zig" ).App ;
25- const Server = @import ("server.zig" ).Server ;
2625const Http = @import ("http/Http.zig" );
27- const Platform = @import ("runtime/js .zig" ).Platform ;
26+ const Server = @import ("server .zig" ).Server ;
2827const Browser = @import ("browser/browser.zig" ).Browser ;
2928
3029const build_config = @import ("build_config" );
@@ -109,13 +108,9 @@ fn run(alloc: Allocator) !void {
109108 log .opts .filter_scopes = lfs ;
110109 }
111110
112- const platform = try Platform .init ();
113- defer platform .deinit ();
114-
115111 // _app is global to handle graceful shutdown.
116112 _app = try App .init (alloc , .{
117113 .run_mode = args .mode ,
118- .platform = & platform ,
119114 .http_proxy = args .httpProxy (),
120115 .proxy_bearer_token = args .proxyBearerToken (),
121116 .tls_verify_host = args .tlsVerifyHost (),
@@ -124,6 +119,7 @@ fn run(alloc: Allocator) !void {
124119 .http_max_host_open = args .httpMaxHostOpen (),
125120 .http_max_concurrent = args .httpMaxConcurrent (),
126121 });
122+
127123 const app = _app .? ;
128124 defer app .deinit ();
129125 app .telemetry .record (.{ .run = {} });
@@ -715,48 +711,50 @@ fn parseCommonArg(
715711 return false ;
716712}
717713
714+ const testing = @import ("testing.zig" );
718715test {
719716 std .testing .refAllDecls (@This ());
720717}
721718
722- var test_wg : std.Thread.WaitGroup = .{} ;
719+ var test_cdp_server : ? Server = null ;
723720test "tests:beforeAll" {
724- try parser .init ();
725721 log .opts .level = .err ;
726722 log .opts .format = .logfmt ;
727723
728- test_wg .startMany (2 );
729- const platform = try Platform .init ();
724+ try testing .setup ();
725+
726+ var wg : std.Thread.WaitGroup = .{};
727+ wg .startMany (2 );
730728
731729 {
732- const address = try std .net .Address .parseIp ("127.0.0.1" , 9582 );
733- const thread = try std .Thread .spawn (.{}, serveHTTP , .{address });
730+ const thread = try std .Thread .spawn (.{}, serveHTTP , .{& wg });
734731 thread .detach ();
735732 }
736733
737734 {
738- const address = try std .net .Address .parseIp ("127.0.0.1" , 9583 );
739- const thread = try std .Thread .spawn (.{}, serveCDP , .{ address , & platform });
735+ const thread = try std .Thread .spawn (.{}, serveCDP , .{& wg });
740736 thread .detach ();
741737 }
742738
743739 // need to wait for the servers to be listening, else tests will fail because
744740 // they aren't able to connect.
745- test_wg .wait ();
741+ wg .wait ();
746742}
747743
748744test "tests:afterAll" {
749- parser .deinit ();
745+ if (test_cdp_server ) | * server | {
746+ server .deinit ();
747+ }
748+ testing .shutdown ();
750749}
751750
752- fn serveHTTP (address : std.net.Address ) ! void {
753- var arena = std .heap .ArenaAllocator .init (std .testing .allocator );
754- defer arena .deinit ();
751+ fn serveHTTP (wg : * std.Thread.WaitGroup ) ! void {
752+ const address = try std .net .Address .parseIp ("127.0.0.1" , 9582 );
755753
756754 var listener = try address .listen (.{ .reuse_address = true });
757755 defer listener .deinit ();
758756
759- test_wg .finish ();
757+ wg .finish ();
760758
761759 var read_buffer : [1024 ]u8 = undefined ;
762760 while (true ) {
@@ -799,20 +797,15 @@ fn serveHTTP(address: std.net.Address) !void {
799797 }
800798}
801799
802- fn serveCDP (address : std.net.Address , platform : * const Platform ) ! void {
803- var gpa : std .heap .GeneralPurposeAllocator (.{}) = .init ;
804- var app = try App .init (gpa .allocator (), .{
805- .run_mode = .serve ,
806- .tls_verify_host = false ,
807- .platform = platform ,
808- .http_max_concurrent = 2 ,
809- });
810- defer app .deinit ();
800+ fn serveCDP (wg : * std.Thread.WaitGroup ) ! void {
801+ const address = try std .net .Address .parseIp ("127.0.0.1" , 9583 );
802+ test_cdp_server = try Server .init (testing .test_app , address );
811803
812- test_wg .finish ();
813- var server = try Server .init (app , address );
804+ var server = try Server .init (testing .test_app , address );
814805 defer server .deinit ();
815- server .run (address , 5 ) catch | err | {
806+ wg .finish ();
807+
808+ test_cdp_server .? .run (address , 5 ) catch | err | {
816809 std .debug .print ("CDP server error: {}" , .{err });
817810 return err ;
818811 };
0 commit comments