import test from "node:test"; import assert from "node:assert/strict"; import { readFile } from "node:fs/promises"; const enableStartup = await readFile(new URL("../src/native-launcher/HotnessEnableStartup.cs", import.meta.url), "utf8"); const disableStartup = await readFile(new URL("../src/native-launcher/HotnessDisableStartup.cs", import.meta.url), "utf8"); const webviewApp = await readFile(new URL("../src/native-launcher/HotnessWebViewApp.cs", import.meta.url), "utf8"); const buildCmd = await readFile(new URL("../生成独立启动器exe(无npm版).cmd", import.meta.url), "utf8"); test("native build script creates only the independent window app helpers without npm", () => { assert.match(buildCmd, /csc\.exe/); assert.match(buildCmd, /开启节目热度采集工具开机自启动\.exe/); assert.match(buildCmd, /取消节目热度采集工具开机自启动\.exe/); assert.match(buildCmd, /节目热度采集工具-独立窗口版\.exe/); assert.match(buildCmd, /HotnessEnableStartup\.cs/); assert.match(buildCmd, /HotnessDisableStartup\.cs/); assert.match(buildCmd, /HotnessWebViewApp\.cs/); }); test("native startup helpers add and remove a Windows startup command", () => { assert.match(enableStartup, /SpecialFolder\.Startup/); assert.match(enableStartup, /节目热度采集工具-开机启动\.cmd/); assert.match(enableStartup, /start \\"\\"/); assert.match(enableStartup, /节目热度采集工具-独立窗口版\.exe/); assert.match(disableStartup, /SpecialFolder\.Startup/); assert.match(disableStartup, /File\.Delete\(startupFile\)/); }); test("native WebView2 app embeds the local tool in an independent window", () => { assert.match(webviewApp, /using Microsoft\.Web\.WebView2\.WinForms/); assert.match(webviewApp, /new WebView2/); assert.match(webviewApp, /CoreWebView2Environment\.CreateAsync/); assert.match(webviewApp, /webView\.Source = new Uri\(appUrl\)/); assert.match(webviewApp, /AppMutexName/); assert.match(webviewApp, /new Mutex\(true, AppMutexName, out createdNew\)/); assert.match(webviewApp, /已经在运行/); assert.match(webviewApp, /CleanupPreviousWebViewServer\(\)/); assert.match(webviewApp, /Process\.GetProcessById\(pid\)/); assert.match(webviewApp, /previous\.Kill\(\)/); assert.match(webviewApp, /ReadJsonInt\(text, "pid"\)/); assert.match(webviewApp, /ProcessStartInfo/); assert.match(webviewApp, /runtime", "node\.exe"/); assert.match(webviewApp, /src", "server\.js"/); assert.match(webviewApp, /json\.Contains\(token\)/); assert.match(webviewApp, /Text = "节目热度采集工具 - " \+ appUrl/); assert.match(webviewApp, /statusLabel\.Text = "已连接:"/); assert.match(webviewApp, /NotifyIcon/); assert.match(webviewApp, /退出后台/); });