Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

browserTabs.test.ts

20 lines1.0 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { 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});