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

electron-launcher.test.mjs

81 lines2.7 KB

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