返回 DeepSeek-Reasonix
startupDelay.test.ts
根目录 / desktop / electron / src / main / startupDelay.test.ts
1 import assert from "node:assert/strict";
2 import { test } from "node:test";
3 import { StartupDelay, renderStartupPage } from "./startupDelay.js";
4 import { startupPresentation } from "./startupPresentation.js";
5
6 function fixture() {
7 const callbacks: (() => void)[] = [];
8 let shown = 0;
9 const delay = new StartupDelay((callback) => { callbacks.push(callback); return () => {}; });
10 return { delay, callbacks, show: () => shown++, shown: () => shown };
11 }
12
13 test("slow startup displays once; repeated clicks do not restart its deadline", () => {
14 const f = fixture();
15 f.delay.start(f.show);
16 assert.equal(f.shown(), 0);
17 for (let i = 0; i < 3; i++) assert.equal(startupPresentation({ serviceReady: false, hasWindow: false, lifecycle: "starting" }), "none");
18 f.callbacks[0]();
19 f.callbacks[0]();
20 assert.equal(f.shown(), 1);
21 assert.equal(startupPresentation({ serviceReady: false, hasWindow: true, lifecycle: "starting" }), "focus");
22 });
23
24 for (const outcome of ["ready", "failed", "quit"]) {
25 test(`${outcome} cancels an already queued startup callback`, () => {
26 const f = fixture();
27 f.delay.start(f.show);
28 f.delay.cancel();
29 f.callbacks[0]();
30 assert.equal(f.shown(), 0);
31 });
32 }
33
34 test("a previous startup cannot display over a newer generation", () => {
35 const f = fixture();
36 f.delay.start(f.show);
37 f.delay.start(f.show);
38 f.callbacks[0]();
39 assert.equal(f.shown(), 0);
40 f.callbacks[1]();
41 assert.equal(f.shown(), 1);
42 });
43
44 test("startup page contains no diagnostic actions or executable script", () => {
45 const html = renderStartupPage();
46 assert.match(html, /正在启动/);
47 assert.doesNotMatch(html, /<script|href=|__shell|Logs:/);
48 assert.match(html, /default-src 'none'/);
49 });
50
50 lines TYPESCRIPT