Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { localPreviewUrlForDevice, loopbackUrlForDevice } from "./browserTabs";
4
5describe("loopbackUrlForDevice", () => {
6 it("opens only the environment's loopback pages on this device", () => {
7 expect(loopbackUrlForDevice("http://localhost:5173/app?x=1")).toBe(
8 "http://localhost:5173/app?x=1",
9 );
10 expect(loopbackUrlForDevice("http://127.0.0.1:3000/")).toBe("http://127.0.0.1:3000/");
11 expect(loopbackUrlForDevice("http://[::1]:3000/")).toBe("http://[::1]:3000/");
12 // The unspecified address would name the phone's own interfaces.
13 expect(loopbackUrlForDevice("http://0.0.0.0:3000/")).toBe("http://localhost:3000/");
14 expect(loopbackUrlForDevice("http://[::]:3000/")).toBe("http://localhost:3000/");
15 expect(loopbackUrlForDevice("https://example.com/")).toBeNull();
16 expect(loopbackUrlForDevice("http://192.168.1.5:3000/")).toBeNull();
17 expect(loopbackUrlForDevice("file:///tmp/a.html")).toBeNull();
18 expect(loopbackUrlForDevice("")).toBeNull();
19 });
20});
21
22describe("localPreviewUrlForDevice", () => {
23 it("loads http and https addresses and nothing else", () => {
24 expect(localPreviewUrlForDevice("http://0.0.0.0:3000/")).toBe("http://localhost:3000/");
25 expect(localPreviewUrlForDevice("https://example.com/docs")).toBe("https://example.com/docs");
26 expect(localPreviewUrlForDevice(" JavaScript:void(0)")).toBeNull();
27 expect(localPreviewUrlForDevice("file:///tmp/a.html")).toBeNull();
28 expect(localPreviewUrlForDevice("data:text/html,hello")).toBeNull();
29 expect(localPreviewUrlForDevice("")).toBeNull();
30 });
31});