@@ -172,13 +172,26 @@ const TestContext = struct {
172172 index : ? usize = null ,
173173 };
174174 pub fn expectSent (self : * TestContext , expected : anytype , opts : SentOpts ) ! void {
175- const serialized = try json .Stringify .valueAlloc (base .arena_allocator , expected , .{
176- .whitespace = .indent_2 ,
177- .emit_null_optional_fields = false ,
178- });
175+ const expected_json = blk : {
176+ // Zig makes this hard. When sendJSON is called, we're sending an anytype.
177+ // We can't record that in an ArrayList(???), so we serialize it to JSON.
178+ // Now, ideally, we could just take our expected structure, serialize it to
179+ // json and check if the two are equal.
180+ // Except serializing to JSON isn't deterministic.
181+ // So we serialize the JSON then we deserialize to json.Value. And then we can
182+ // compare our anytype expectation with the json.Value that we captured
183+
184+ const serialized = try json .Stringify .valueAlloc (base .arena_allocator , expected , .{
185+ .whitespace = .indent_2 ,
186+ .emit_null_optional_fields = false ,
187+ });
188+
189+ break :blk try std .json .parseFromSliceLeaky (json .Value , base .arena_allocator , serialized , .{});
190+ };
191+
179192 for (0.. 5) | _ | {
180193 for (self .received .items , 0.. ) | received , i | {
181- if (try compareExpectedToSent ( serialized , received ) == false ) {
194+ if (try base . isEqualJson ( expected_json , received ) == false ) {
182195 continue ;
183196 }
184197
@@ -191,6 +204,15 @@ const TestContext = struct {
191204 }
192205 return ;
193206 }
207+
208+ if (self .cdp_ ) | * cdp__ | {
209+ if (cdp__ .browser_context ) | * bc | {
210+ if (bc .session .page != null ) {
211+ var runner = try bc .session .runner (.{});
212+ _ = try runner .tick (.{.ms = 1000 });
213+ }
214+ }
215+ }
194216 std .Thread .sleep (5 * std .time .ns_per_ms );
195217 try self .read ();
196218 }
@@ -303,17 +325,3 @@ pub fn context() !TestContext {
303325 .socket = pair [0 ],
304326 };
305327}
306-
307- // Zig makes this hard. When sendJSON is called, we're sending an anytype.
308- // We can't record that in an ArrayList(???), so we serialize it to JSON.
309- // Now, ideally, we could just take our expected structure, serialize it to
310- // json and check if the two are equal.
311- // Except serializing to JSON isn't deterministic.
312- // So we serialize the JSON then we deserialize to json.Value. And then we can
313- // compare our anytype expectation with the json.Value that we captured
314-
315- fn compareExpectedToSent (expected : []const u8 , actual : json.Value ) ! bool {
316- const expected_value = try std .json .parseFromSlice (json .Value , std .testing .allocator , expected , .{});
317- defer expected_value .deinit ();
318- return base .isEqualJson (expected_value .value , actual );
319- }
0 commit comments