@foxglove/embed 0.92.0 → 0.93.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.
|
|
3
|
+
"version": "0.93.0",
|
|
4
4
|
"homepage": "https://foxglove.dev/",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -21,13 +21,15 @@
|
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "tsc -b tsconfig.build.json",
|
|
23
23
|
"clean": "node ../../scripts/cleanBuildArtifacts.mjs",
|
|
24
|
-
"prepack": "yarn build"
|
|
24
|
+
"prepack": "yarn build",
|
|
25
|
+
"test": "vitest"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"@foxglove/tsconfig": "3.2.0",
|
|
28
|
-
"@swc/core": "1.15.5",
|
|
29
|
-
"@swc/jest": "0.2.39",
|
|
30
29
|
"@testing-library/dom": "10.4.1",
|
|
31
|
-
"
|
|
30
|
+
"jsdom": "26.1.0",
|
|
31
|
+
"typescript": "6.0.3",
|
|
32
|
+
"vite": "8.0.16",
|
|
33
|
+
"vitest": "5.1.0"
|
|
32
34
|
}
|
|
33
35
|
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
MessageChannel as NodeMessageChannel,
|
|
4
4
|
MessagePort as NodeMessagePort,
|
|
5
5
|
} from "node:worker_threads";
|
|
6
|
+
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
7
|
|
|
7
8
|
import { FoxgloveViewer } from "./FoxgloveViewer.ts";
|
|
8
9
|
import { IframeCapability, type IframeCommand } from "./commands.ts";
|
|
@@ -11,7 +12,7 @@ import type { DataSource } from "./types.ts";
|
|
|
11
12
|
function capturePostedMessages(iframe: HTMLIFrameElement): IframeCommand[] {
|
|
12
13
|
const messages: IframeCommand[] = [];
|
|
13
14
|
const original = iframe.contentWindow!.postMessage.bind(iframe.contentWindow!);
|
|
14
|
-
|
|
15
|
+
vi.spyOn(iframe.contentWindow!, "postMessage").mockImplementation((msg, ...args) => {
|
|
15
16
|
messages.push(msg as IframeCommand);
|
|
16
17
|
original(msg, ...args);
|
|
17
18
|
});
|
|
@@ -124,7 +125,7 @@ describe("FoxgloveViewer parent transport", () => {
|
|
|
124
125
|
document.body.appendChild(parent);
|
|
125
126
|
const viewer = new FoxgloveViewer({ parent, orgSlug: undefined });
|
|
126
127
|
const iframe = getIframe(parent);
|
|
127
|
-
const onCapabilities =
|
|
128
|
+
const onCapabilities = vi.fn();
|
|
128
129
|
viewer.addEventListener("capabilities", onCapabilities);
|
|
129
130
|
|
|
130
131
|
expect(viewer.getCapabilities()).toEqual({ parentOwnedLiveTransport: "pending" });
|
|
@@ -183,7 +184,7 @@ describe("FoxgloveViewer parent transport", () => {
|
|
|
183
184
|
type: "live",
|
|
184
185
|
protocol: "foxglove-websocket",
|
|
185
186
|
url: "virtual://robot",
|
|
186
|
-
transport: () => ({ send:
|
|
187
|
+
transport: () => ({ send: vi.fn(), close: vi.fn() }),
|
|
187
188
|
},
|
|
188
189
|
});
|
|
189
190
|
const iframe = getIframe(parent);
|
|
@@ -212,7 +213,7 @@ describe("FoxgloveViewer parent transport", () => {
|
|
|
212
213
|
it("sends a parent-owned remote data loader without exposing its transport", () => {
|
|
213
214
|
const parent = document.createElement("div");
|
|
214
215
|
document.body.appendChild(parent);
|
|
215
|
-
const transport =
|
|
216
|
+
const transport = vi.fn();
|
|
216
217
|
const viewer = new FoxgloveViewer({
|
|
217
218
|
parent,
|
|
218
219
|
orgSlug: undefined,
|
|
@@ -260,7 +261,7 @@ describe("FoxgloveViewer parent transport", () => {
|
|
|
260
261
|
});
|
|
261
262
|
const iframe = getIframe(parent);
|
|
262
263
|
const messages = capturePostedMessages(iframe);
|
|
263
|
-
const onError =
|
|
264
|
+
const onError = vi.fn();
|
|
264
265
|
viewer.addEventListener("error", onError);
|
|
265
266
|
|
|
266
267
|
simulateHandshakeRequest(viewer, iframe);
|
|
@@ -292,12 +293,12 @@ describe("FoxgloveViewer parent transport", () => {
|
|
|
292
293
|
initialDataSource: {
|
|
293
294
|
type: "remote-data-loader",
|
|
294
295
|
manifestParams: { recording: "first-recording" },
|
|
295
|
-
transport:
|
|
296
|
+
transport: vi.fn(),
|
|
296
297
|
},
|
|
297
298
|
});
|
|
298
299
|
const iframe = getIframe(parent);
|
|
299
300
|
const messages = capturePostedMessages(iframe);
|
|
300
|
-
const onError =
|
|
301
|
+
const onError = vi.fn();
|
|
301
302
|
viewer.addEventListener("error", onError);
|
|
302
303
|
|
|
303
304
|
simulateHandshakeRequest(viewer, iframe, [IframeCapability.parentOwnedLiveTransport]);
|
|
@@ -323,7 +324,7 @@ describe("FoxgloveViewer parent transport", () => {
|
|
|
323
324
|
const viewer = new FoxgloveViewer({ parent, orgSlug: undefined });
|
|
324
325
|
const iframe = getIframe(parent);
|
|
325
326
|
const messages = capturePostedMessages(iframe);
|
|
326
|
-
const transport = () => ({ send:
|
|
327
|
+
const transport = () => ({ send: vi.fn(), close: vi.fn() });
|
|
327
328
|
|
|
328
329
|
simulateHandshakeRequest(viewer, iframe);
|
|
329
330
|
messages.length = 0;
|
|
@@ -354,12 +355,12 @@ describe("FoxgloveViewer parent transport", () => {
|
|
|
354
355
|
type: "live",
|
|
355
356
|
protocol: "foxglove-websocket",
|
|
356
357
|
url: "virtual://robot",
|
|
357
|
-
transport: () => ({ send:
|
|
358
|
+
transport: () => ({ send: vi.fn(), close: vi.fn() }),
|
|
358
359
|
},
|
|
359
360
|
});
|
|
360
361
|
const iframe = getIframe(parent);
|
|
361
362
|
const messages = capturePostedMessages(iframe);
|
|
362
|
-
const onError =
|
|
363
|
+
const onError = vi.fn();
|
|
363
364
|
viewer.addEventListener("error", onError);
|
|
364
365
|
|
|
365
366
|
simulateHandshakeRequest(viewer, iframe, []);
|
|
@@ -388,7 +389,7 @@ describe("FoxgloveViewer parent transport", () => {
|
|
|
388
389
|
const viewer = new FoxgloveViewer({ parent, orgSlug: undefined });
|
|
389
390
|
const iframe = getIframe(parent);
|
|
390
391
|
const messages = capturePostedMessages(iframe);
|
|
391
|
-
const onError =
|
|
392
|
+
const onError = vi.fn();
|
|
392
393
|
viewer.addEventListener("error", onError);
|
|
393
394
|
|
|
394
395
|
simulateHandshakeRequest(viewer, iframe, []);
|
|
@@ -397,7 +398,7 @@ describe("FoxgloveViewer parent transport", () => {
|
|
|
397
398
|
type: "live",
|
|
398
399
|
protocol: "foxglove-websocket",
|
|
399
400
|
url: "virtual://robot",
|
|
400
|
-
transport: () => ({ send:
|
|
401
|
+
transport: () => ({ send: vi.fn(), close: vi.fn() }),
|
|
401
402
|
});
|
|
402
403
|
|
|
403
404
|
expect(messages).toHaveLength(0);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
1
3
|
import { ParentFetchBridge } from "./ParentFetchBridge.ts";
|
|
2
4
|
|
|
3
5
|
async function nextMessage<T>(port: MessagePort): Promise<T> {
|
|
@@ -17,7 +19,7 @@ async function nextMessage<T>(port: MessagePort): Promise<T> {
|
|
|
17
19
|
|
|
18
20
|
describe("ParentFetchBridge", () => {
|
|
19
21
|
it("streams a response through the parent", async () => {
|
|
20
|
-
const fetchFn =
|
|
22
|
+
const fetchFn = vi.fn(async () => {
|
|
21
23
|
return new Response(new Uint8Array([1, 2, 3]), {
|
|
22
24
|
status: 200,
|
|
23
25
|
headers: { "content-type": "application/octet-stream" },
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { describe, expect, it, vi, type Mock } from "vitest";
|
|
2
|
+
|
|
1
3
|
import { ParentTransportBridge } from "./ParentTransportBridge.ts";
|
|
2
4
|
import type { ParentTransportFactoryArgs } from "./types.ts";
|
|
3
5
|
|
|
@@ -17,10 +19,10 @@ async function nextMessage<T>(port: MessagePort): Promise<T> {
|
|
|
17
19
|
describe("ParentTransportBridge", () => {
|
|
18
20
|
it("carries text and binary Foxglove frames in both directions", async () => {
|
|
19
21
|
const sendCalled = Promise.withResolvers<void>();
|
|
20
|
-
const send =
|
|
22
|
+
const send = vi.fn(() => {
|
|
21
23
|
sendCalled.resolve();
|
|
22
24
|
});
|
|
23
|
-
const close =
|
|
25
|
+
const close = vi.fn();
|
|
24
26
|
const factoryArgsReady = Promise.withResolvers<ParentTransportFactoryArgs>();
|
|
25
27
|
const bridge = new ParentTransportBridge((args) => {
|
|
26
28
|
factoryArgsReady.resolve(args);
|
|
@@ -66,10 +68,10 @@ describe("ParentTransportBridge", () => {
|
|
|
66
68
|
});
|
|
67
69
|
|
|
68
70
|
it("creates a fresh parent connection when the viewer reconnects", async () => {
|
|
69
|
-
const connections: { close:
|
|
71
|
+
const connections: { close: Mock }[] = [];
|
|
70
72
|
const secondConnectionCreated = Promise.withResolvers<void>();
|
|
71
73
|
const bridge = new ParentTransportBridge(() => {
|
|
72
|
-
const connection = { send:
|
|
74
|
+
const connection = { send: vi.fn(), close: vi.fn() };
|
|
73
75
|
connections.push(connection);
|
|
74
76
|
if (connections.length === 2) {
|
|
75
77
|
secondConnectionCreated.resolve();
|