| 1 | // @effect-diagnostics nodeBuiltinImport:off - Exercises the actual CLI in isolated child processes. |
| 2 | import * as NodeChildProcess from "node:child_process"; |
| 3 | import * as NodeFSP from "node:fs/promises"; |
| 4 | import * as NodeOS from "node:os"; |
| 5 | import * as NodePath from "node:path"; |
| 6 | import * as NodeURL from "node:url"; |
| 7 | import * as NodeUtil from "node:util"; |
| 8 | import { afterAll, beforeAll, expect, it } from "vite-plus/test"; |
| 9 | |
| 10 | import packageJson from "../package.json" with { type: "json" }; |
| 11 | |
| 12 | const run = NodeUtil.promisify(NodeChildProcess.execFile); |
| 13 | let home: string; |
| 14 | |
| 15 | beforeAll(async () => { |
| 16 | home = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "knife-version-")); |
| 17 | }); |
| 18 | |
| 19 | afterAll(async () => { |
| 20 | await NodeFSP.rm(home, { recursive: true, force: true }); |
| 21 | }); |
| 22 | |
| 23 | it.each([ |
| 24 | [undefined, packageJson.version], |
| 25 | ["0.0.1234567890", "0.0.1234567890"], |
| 26 | ["9.0.1", packageJson.version], |
| 27 | ])("reports the running server version for override %s", async (override, expected) => { |
| 28 | const env: NodeJS.ProcessEnv = { ...process.env, T3CODE_HOME: home }; |
| 29 | delete env.T3CODE_VERSION_OVERRIDE; |
| 30 | if (override !== undefined) env.T3CODE_VERSION_OVERRIDE = override; |
| 31 | const { stdout } = await run( |
| 32 | process.execPath, |
| 33 | [NodeURL.fileURLToPath(new URL("./bin.ts", import.meta.url)), "--version"], |
| 34 | { env }, |
| 35 | ); |
| 36 | expect(stdout.trim()).toBe(`t3 v${expected}`); |
| 37 | }); |