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

crash-log-model.test.ts

73 lines2.7 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { formatStartupCrashReport, parseStartupCrashRecords } from "./crash-log-model";
4​
5const BUNDLE =
6 "/Users/expo/workingdir/build/apps/mobile/ios/build/Build/Intermediates.noindex/ArchiveIntermediates/T3Code/BuildProductsPath/Release-iphoneos/main.jsbundle";
7const FATAL = {
8 timestamp: 1789277752000,
9 level: "error",
10 code: "JSRuntimeError",
11 message: [
12 "ErrorRecovery fatal exception: Fatal error: Time: 1789277752033.127930",
13 "Domain: RCTErrorDomain",
14 "Code: 0",
15 "Description: Unhandled JS Exception: TypeError: Cannot read property 'defaultModelSelection' of null",
16 "",
17 "This error is located at:",
18 ` at NewTaskFlowProvider (${BUNDLE}:590585:51)`,
19 ` at NavigationProvider (${BUNDLE}:139067:3)`,
20 " at RNSSafeAreaView (<anonymous>)",
21 ].join("\n"),
22};
23​
24describe("parseStartupCrashRecords", () => {
25 it("extracts the JS error and a compact component stack from a fatal entry", () => {
26 const [record] = parseStartupCrashRecords([FATAL]);
27 expect(record?.description).toBe(
28 "TypeError: Cannot read property 'defaultModelSelection' of null",
29 );
30 expect(record?.frames).toEqual([
31 "NewTaskFlowProvider (main.jsbundle:590585:51)",
32 "NavigationProvider (main.jsbundle:139067:3)",
33 "RNSSafeAreaView",
34 ]);
35 expect(record?.detail).toContain("Domain: RCTErrorDomain");
36 });
37​
38 it("ignores update-check noise and orders crashes newest first", () => {
39 const records = parseStartupCrashRecords([
40 { timestamp: 1, level: "info", code: "NoUpdatesAvailable", message: "checked" },
41 { ...FATAL, timestamp: 10 },
42 { timestamp: 5, level: "error", code: "UpdateFailedToLoad", message: "nope" },
43 { ...FATAL, timestamp: 20 },
44 ]);
45 expect(records.map((record) => record.timestamp)).toEqual([20, 10]);
46 });
47​
48 it("skips a runtime error entry without a description line", () => {
49 expect(
50 parseStartupCrashRecords([
51 { ...FATAL, message: "ErrorRecovery fatal exception: Fatal exception: Name: x" },
52 ]),
53 ).toEqual([]);
54 });
55});
56​
57describe("formatStartupCrashReport", () => {
58 it("writes the app version and each crash's full detail", () => {
59 const report = formatStartupCrashReport(parseStartupCrashRecords([FATAL]), {
60 version: "1.1.1",
61 build: "56",
62 });
63 expect(report.startsWith("T3 Code 1.1.1 (56)\n")).toBe(true);
64 expect(report).toContain("2026-09-13T05:35:52.000Z");
65 expect(report).toContain("at NewTaskFlowProvider");
66 });
67​
68 it("says so when nothing was recorded", () => {
69 expect(formatStartupCrashReport([], { version: "1.1.1", build: "56" })).toBe(
70 "T3 Code 1.1.1 (56)\nNo startup crashes recorded.",
71 );
72 });
73});