返回 CodeWhale
install-platform.test.ts
根目录 / web / lib / install-platform.test.ts
1 import { describe, expect, it } from "vitest";
2 import { detectFromBrowserSignals } from "./install-platform";
3
4 describe("install platform detection", () => {
5 const frozenWindowsUa =
6 "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36";
7
8 it("uses User-Agent Client Hints for native Windows ARM64", () => {
9 expect(
10 detectFromBrowserSignals(frozenWindowsUa, {
11 architecture: "arm",
12 bitness: "64",
13 }),
14 ).toBe("windows-arm64");
15 });
16
17 it("keeps frozen Windows user agents on x64 without an ARM hint", () => {
18 expect(detectFromBrowserSignals(frozenWindowsUa)).toBe("windows-x64");
19 });
20
21 it("retains the legacy ARM token fallback", () => {
22 expect(detectFromBrowserSignals("Mozilla/5.0 (Windows NT 10.0; ARM64)")).toBe(
23 "windows-arm64",
24 );
25 });
26
27 const frozenMacUa =
28 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36";
29
30 it("detects Intel Macs through User-Agent Client Hints (#5168)", () => {
31 expect(
32 detectFromBrowserSignals(frozenMacUa, {
33 architecture: "x86",
34 bitness: "64",
35 }),
36 ).toBe("macos-x64");
37 });
38
39 it("detects Apple Silicon through User-Agent Client Hints", () => {
40 expect(
41 detectFromBrowserSignals(frozenMacUa, {
42 architecture: "arm",
43 bitness: "64",
44 }),
45 ).toBe("macos-arm64");
46 });
47
48 it("defaults to arm64 without hints because the frozen Mac UA cannot distinguish", () => {
49 // Since Big Sur the UA says "Intel Mac OS X" on Apple Silicon too, so
50 // UA parsing must not route anyone to x64. The install page's arch
51 // chooser is the honest fallback for Intel users without hints.
52 expect(detectFromBrowserSignals(frozenMacUa)).toBe("macos-arm64");
53 });
54 });
55
55 lines TYPESCRIPT