mirror of
https://github.com/morluto/rea
synced 2026-10-27 14:42:18 -04:00
test(browser): verify out-of-order response correlation
This commit is contained in:
@@ -107,7 +107,7 @@ describe("CDP connection admission cancellation", () => {
|
||||
|
||||
describe("CDP connection response correlation", () => {
|
||||
it("correlates concurrent command responses over a real WebSocket", async () => {
|
||||
const browser = await startFakeCdpBrowser();
|
||||
const browser = await startFakeCdpBrowser({ hangOnMethod: "Page.enable" });
|
||||
browsers.push(browser);
|
||||
const connection = await CdpConnection.connect(
|
||||
browser.browserWebSocketUrl,
|
||||
@@ -124,6 +124,28 @@ describe("CDP connection response correlation", () => {
|
||||
});
|
||||
browser.emitRawMessage(JSON.stringify({ id: 999 }));
|
||||
await expect(connection.send("Runtime.enable")).resolves.toEqual({});
|
||||
const first = connection.send("Page.enable", { selected: "first" });
|
||||
const second = connection.send("Page.enable", { selected: "second" });
|
||||
const replies = Promise.all([first, second]);
|
||||
await vi.waitFor(() => expect(browser.commands).toHaveLength(5));
|
||||
const firstCommand = browser.commands[3];
|
||||
const secondCommand = browser.commands[4];
|
||||
if (firstCommand === undefined || secondCommand === undefined)
|
||||
throw new Error("Fake browser did not receive both pending commands");
|
||||
browser.emitRawMessage(
|
||||
JSON.stringify({
|
||||
id: secondCommand.id,
|
||||
result: { selected: "second" },
|
||||
}),
|
||||
);
|
||||
browser.emitRawMessage(
|
||||
JSON.stringify({ id: firstCommand.id, result: { selected: "first" } }),
|
||||
);
|
||||
await expect(replies).resolves.toEqual([
|
||||
{ selected: "first" },
|
||||
{ selected: "second" },
|
||||
]);
|
||||
await expect(connection.send("Runtime.enable")).resolves.toEqual({});
|
||||
} finally {
|
||||
await connection.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user