|
| 1 | +import { test, expect, mock } from "bun:test" |
| 2 | + |
| 3 | +// Mock the native modules BEFORE importing the collector. |
| 4 | +mock.module("react-native", () => ({ |
| 5 | + Platform: { OS: "ios", Version: "17.4" }, |
| 6 | + Dimensions: { |
| 7 | + get: (k: "window" | "screen") => |
| 8 | + k === "window" ? { width: 390, height: 844 } : { width: 1179, height: 2556 }, |
| 9 | + }, |
| 10 | + PixelRatio: { get: () => 3 }, |
| 11 | +})) |
| 12 | +mock.module("expo-device", () => ({ |
| 13 | + modelName: "iPhone 15", |
| 14 | +})) |
| 15 | +mock.module("expo-constants", () => ({ |
| 16 | + default: { expoConfig: { version: "1.2.3" }, nativeBuildVersion: "42" }, |
| 17 | +})) |
| 18 | +mock.module("@react-native-community/netinfo", () => ({ |
| 19 | + fetch: async () => ({ |
| 20 | + isConnected: true, |
| 21 | + details: { effectiveType: "4g", rtt: 50, downlink: 10 }, |
| 22 | + }), |
| 23 | +})) |
| 24 | + |
| 25 | +test("assembles a mobile SystemInfo record", async () => { |
| 26 | + const { collectSystemInfo } = await import("./system-info") |
| 27 | + const info = await collectSystemInfo({ pageUrl: "myapp://home" }) |
| 28 | + expect(info.devicePlatform).toBe("ios") |
| 29 | + expect(info.deviceModel).toBe("iPhone 15") |
| 30 | + expect(info.appVersion).toBe("1.2.3") |
| 31 | + expect(info.appBuild).toBe("42") |
| 32 | + expect(info.osVersion).toBe("17.4") |
| 33 | + expect(info.viewport).toEqual({ w: 390, h: 844 }) |
| 34 | + expect(info.screen).toEqual({ w: 1179, h: 2556 }) |
| 35 | + expect(info.dpr).toBe(3) |
| 36 | + expect(info.online).toBe(true) |
| 37 | + expect(info.connection?.effectiveType).toBe("4g") |
| 38 | + expect(info.pageUrl).toBe("myapp://home") |
| 39 | + expect(info.userAgent).toMatch(/Expo/) |
| 40 | +}) |
0 commit comments