Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/web/src/__tests__/devtools-binding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,27 @@ describe("the devtools binding transport", () => {
const { devtools, events } = setup();

devtools.receive(JSON.stringify({ kind: "open" }));
devtools.receive(JSON.stringify({ kind: "message", text: '{"type":"y"}' }));

expect(events).toEqual(["open", 'message:{"type":"y"}']);
});

it("still delivers what the relay tags for the new socket after dropping the old one's", () => {
const { devtools, socket, sent } = setup();
const first = sent[0]!.id;
socket.close(1000, "superseded");
const events: string[] = [];
devtools.transport.open("ws://127.0.0.1:49152", {
open: () => events.push("open"),
message: (text) => events.push(`message:${text}`),
close: (code, reason) => events.push(`close:${code}:${reason}`),
error: (message) => events.push(`error:${message}`),
});
const second = sent.filter((message) => message.kind === "open")[1]!.id;

devtools.receive(JSON.stringify({ kind: "open", id: first }));
devtools.receive(JSON.stringify({ kind: "close", id: first, code: 1006, reason: "" }));
devtools.receive(JSON.stringify({ kind: "open", id: second }));

expect(events).toEqual(["open"]);
});
Expand Down
3 changes: 2 additions & 1 deletion packages/web/src/browser/devtools-binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import type { SocketEvents, Transport } from "../core/index.js";
*
* Every message carries the `id` of the socket it is about, chosen by the page on `open`. The
* relay echoes it, so a message queued for a socket the page has since replaced is dropped
* instead of reaching the new one. A message without an `id` goes to the active socket.
* instead of reaching the new one. A message without an `id` (an older relay, or `attachPage`
* closing the page's socket) goes to the active socket.
*/
export const createDevtoolsBindingTransport = (
sendToRelay: (json: string) => void,
Expand Down
Loading