@foxglove/embed 0.70.0 → 0.71.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foxglove/embed",
3
- "version": "0.70.0",
3
+ "version": "0.71.0",
4
4
  "homepage": "https://foxglove.dev/",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -16,14 +16,14 @@ async function nextMessage<T>(port: MessagePort): Promise<T> {
16
16
 
17
17
  describe("ParentTransportBridge", () => {
18
18
  it("carries text and binary Foxglove frames in both directions", async () => {
19
- const send = jest.fn();
20
- const close = jest.fn();
21
- let resolveFactoryArgs!: (args: ParentTransportFactoryArgs) => void;
22
- const factoryArgsPromise = new Promise<ParentTransportFactoryArgs>((resolve) => {
23
- resolveFactoryArgs = resolve;
19
+ const sendCalled = Promise.withResolvers<void>();
20
+ const send = jest.fn(() => {
21
+ sendCalled.resolve();
24
22
  });
23
+ const close = jest.fn();
24
+ const factoryArgsReady = Promise.withResolvers<ParentTransportFactoryArgs>();
25
25
  const bridge = new ParentTransportBridge((args) => {
26
- resolveFactoryArgs(args);
26
+ factoryArgsReady.resolve(args);
27
27
  return { send, close };
28
28
  });
29
29
 
@@ -32,7 +32,7 @@ describe("ParentTransportBridge", () => {
32
32
  url: "virtual://robot",
33
33
  protocols: ["foxglove.websocket.v1"],
34
34
  });
35
- const factoryArgs = await factoryArgsPromise;
35
+ const factoryArgs = await factoryArgsReady.promise;
36
36
 
37
37
  expect(factoryArgs).toMatchObject({
38
38
  url: "virtual://robot",
@@ -47,7 +47,7 @@ describe("ParentTransportBridge", () => {
47
47
  });
48
48
 
49
49
  bridge.port.postMessage({ type: "send", data: "subscribe" });
50
- await new Promise((resolve) => setTimeout(resolve, 0));
50
+ await sendCalled.promise;
51
51
  expect(send).toHaveBeenCalledWith("subscribe");
52
52
 
53
53
  const binaryMessage = nextMessage<{ type: string; data: ArrayBuffer }>(bridge.port);
@@ -67,22 +67,19 @@ describe("ParentTransportBridge", () => {
67
67
 
68
68
  it("creates a fresh parent connection when the viewer reconnects", async () => {
69
69
  const connections: { close: jest.Mock }[] = [];
70
- let resolveSecondConnection!: () => void;
71
- const secondConnection = new Promise<void>((resolve) => {
72
- resolveSecondConnection = resolve;
73
- });
70
+ const secondConnectionCreated = Promise.withResolvers<void>();
74
71
  const bridge = new ParentTransportBridge(() => {
75
72
  const connection = { send: jest.fn(), close: jest.fn() };
76
73
  connections.push(connection);
77
74
  if (connections.length === 2) {
78
- resolveSecondConnection();
75
+ secondConnectionCreated.resolve();
79
76
  }
80
77
  return connection;
81
78
  });
82
79
 
83
80
  bridge.port.postMessage({ type: "connect", url: "virtual://robot", protocols: [] });
84
81
  bridge.port.postMessage({ type: "connect", url: "virtual://robot", protocols: [] });
85
- await secondConnection;
82
+ await secondConnectionCreated.promise;
86
83
 
87
84
  expect(connections).toHaveLength(2);
88
85
  expect(connections[0]!.close).toHaveBeenCalledTimes(1);