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

electron-launcher.test.mjs

92 lines3.3 KB

1import { assert, describe, it } from "vite-plus/test";
2​
3import {
4 makeDevelopmentLauncherScript,
5 resolveElectronBinaryPath,
6 resolveMacLauncherIconPaths,
7 resolveMacLauncherPaths,
8} from "./electron-launcher.mjs";
9​
10describe("electron development launcher", () => {
11 it("uses captured values only as fallbacks for a live runner environment", () => {
12 const script = makeDevelopmentLauncherScript({
13 electronBinaryPath: "/repo/node_modules/electron/Electron",
14 mainEntryPath: "/repo/apps/desktop/dist-electron/main.cjs",
15 desktopRoot: "/repo/apps/desktop",
16 environment: {
17 VITE_DEV_SERVER_URL: "http://127.0.0.1:8526",
18 T3CODE_PORT: "16566",
19 T3CODE_HOME: "/tmp/t3",
20 },
21 });
22​
23 assert.include(
24 script,
25 "if [ -z \"${VITE_DEV_SERVER_URL:-}\" ]; then export VITE_DEV_SERVER_URL='http://127.0.0.1:8526'; fi",
26 );
27 assert.notInclude(script, "\nexport VITE_DEV_SERVER_URL=");
28 assert.include(
29 script,
30 "exec '/repo/node_modules/electron/Electron' --t3code-dev-root='/repo/apps/desktop' '/repo/apps/desktop/dist-electron/main.cjs' \"$@\"",
31 );
32 });
33​
34 it("repairs Electron before loading the package entrypoint", () => {
35 const calls = [];
36 const electronPath = resolveElectronBinaryPath({
37 ensureRuntime: () => {
38 calls.push("ensure");
39 },
40 createRequire: () => (specifier) => {
41 calls.push(`require:${specifier}`);
42 return "/repo/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron";
43 },
44 moduleUrl: import.meta.url,
45 });
46​
47 assert.equal(
48 electronPath,
49 "/repo/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron",
50 );
51 assert.deepEqual(calls, ["ensure", "require:electron"]);
52 });
53​
54 it("keeps the native Electron executable name inside the branded macOS bundle", () => {
55 const paths = resolveMacLauncherPaths(
56 "/repo/apps/desktop/.electron-runtime/T3 Code (Dev).app",
57 "T3 Code (Dev)",
58 );
59​
60 assert.equal(paths.launcherExecutableName, "T3 Code (Dev) Launcher");
61 assert.equal(
62 paths.launcherBinaryPath,
63 "/repo/apps/desktop/.electron-runtime/T3 Code (Dev).app/Contents/MacOS/T3 Code (Dev) Launcher",
64 );
65 assert.equal(
66 paths.runtimeElectronBinaryPath,
67 "/repo/apps/desktop/.electron-runtime/T3 Code (Dev).app/Contents/MacOS/Electron",
68 );
69​
70 const script = makeDevelopmentLauncherScript({
71 electronBinaryPath: paths.runtimeElectronBinaryPath,
72 mainEntryPath: "/repo/apps/desktop/dist-electron/main.cjs",
73 desktopRoot: "/repo/apps/desktop",
74 environment: {},
75 });
76 assert.include(
77 script,
78 "exec '/repo/apps/desktop/.electron-runtime/T3 Code (Dev).app/Contents/MacOS/Electron'",
79 );
80 assert.notInclude(script, "node_modules/electron");
81 });
82​
83 it("derives launcher icons from canonical development and production assets", () => {
84 const development = resolveMacLauncherIconPaths("/runtime", true);
85 const production = resolveMacLauncherIconPaths("/runtime", false);
86​
87 assert.match(development.sourceIconPath, /assets\/dev\/blueprint-macos-1024\.png$/);
88 assert.equal(development.generatedIconPath, "/runtime/icon-dev.icns");
89 assert.match(production.sourceIconPath, /assets\/prod\/black-macos-1024\.png$/);
90 assert.equal(production.generatedIconPath, "/runtime/icon-prod.icns");
91 });
92});