|
| 1 | +import * as NodeChildProcess from "node:child_process"; |
1 | 2 | import * as NodeFSP from "node:fs/promises"; |
2 | 3 | import * as NodeOS from "node:os"; |
3 | 4 | import * as NodePath from "node:path"; |
@@ -108,3 +109,65 @@ void import("./linux.ts").then(({ result }) => process.emit("ready", result));`, |
108 | 109 | await NodeFSP.rm(directory, { recursive: true, force: true }); |
109 | 110 | } |
110 | 111 | }); |
| 112 | + |
| 113 | +it("loads the emitted packaged boot entry and backend cache preload", async () => { |
| 114 | + const directory = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-desktop-boot-")); |
| 115 | + try { |
| 116 | + const entries = ["src/boot.ts", "src/compileCache.ts"]; |
| 117 | + await NodeFSP.mkdir(NodePath.join(directory, "src")); |
| 118 | + await Promise.all( |
| 119 | + entries.map((entry) => |
| 120 | + NodeFSP.copyFile(new URL(`../${entry}`, import.meta.url), NodePath.join(directory, entry)), |
| 121 | + ), |
| 122 | + ); |
| 123 | + assert.ok(Array.isArray(desktopConfig.pack)); |
| 124 | + for (const packConfig of desktopConfig.pack) { |
| 125 | + if (!Array.isArray(packConfig.entry)) continue; |
| 126 | + if (!packConfig.entry.some((entry) => entries.includes(entry))) continue; |
| 127 | + await build({ |
| 128 | + ...packConfig, |
| 129 | + config: false, |
| 130 | + cwd: directory, |
| 131 | + tsconfig: false, |
| 132 | + sourcemap: false, |
| 133 | + onSuccess: undefined, |
| 134 | + logLevel: "silent", |
| 135 | + }); |
| 136 | + } |
| 137 | + const outputDirectory = NodePath.join(directory, "dist-electron"); |
| 138 | + const fixture = `console.log(require('node:module').getCompileCacheDir() ? 'cached' : 'uncached');`; |
| 139 | + await NodeFSP.writeFile(NodePath.join(outputDirectory, "main.cjs"), fixture); |
| 140 | + await NodeFSP.writeFile( |
| 141 | + NodePath.join(outputDirectory, "backend.mjs"), |
| 142 | + `import { getCompileCacheDir } from 'node:module'; console.log(getCompileCacheDir() ? 'cached' : 'uncached');`, |
| 143 | + ); |
| 144 | + for (const disabled of [false, true]) { |
| 145 | + for (const args of [ |
| 146 | + [NodePath.join(outputDirectory, "boot.cjs")], |
| 147 | + [ |
| 148 | + "--require", |
| 149 | + NodePath.join(outputDirectory, "compileCache.cjs"), |
| 150 | + NodePath.join(outputDirectory, "backend.mjs"), |
| 151 | + ], |
| 152 | + ]) { |
| 153 | + const child = NodeChildProcess.spawnSync(process.execPath, args, { |
| 154 | + encoding: "utf8", |
| 155 | + env: { |
| 156 | + ...process.env, |
| 157 | + APPIMAGE: "", |
| 158 | + NODE_COMPILE_CACHE: undefined, |
| 159 | + NODE_DISABLE_COMPILE_CACHE: disabled ? "1" : undefined, |
| 160 | + XDG_CACHE_HOME: directory, |
| 161 | + TMPDIR: directory, |
| 162 | + TEMP: directory, |
| 163 | + TMP: directory, |
| 164 | + }, |
| 165 | + }); |
| 166 | + assert.equal(child.status, 0, child.stderr); |
| 167 | + assert.equal(child.stdout.trim(), disabled ? "uncached" : "cached"); |
| 168 | + } |
| 169 | + } |
| 170 | + } finally { |
| 171 | + await NodeFSP.rm(directory, { recursive: true, force: true }); |
| 172 | + } |
| 173 | +}); |
0 commit comments