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

deviceHubNodeArgs.test.ts

59 lines2.1 KB

1// @effect-diagnostics nodeBuiltinImport:off - exercises the standalone Node preload in a subprocess.
2import { describe, expect, it } from "@effect/vitest";
3import * as NodeChildProcess from "node:child_process";
4import * as NodeUtil from "node:util";
5​
6import { deviceHubNodeArgs } from "./deviceHubNodeArgs.ts";
7​
8const exec = NodeUtil.promisify(NodeChildProcess.execFile);
9​
10describe("deviceHubNodeArgs", () => {
11 it("hides emulator consoles without changing other hub children or arguments", async () => {
12 const capture = `
13import childProcess from "node:child_process";
14import { syncBuiltinESMExports } from "node:module";
15childProcess.spawn = (...args) => console.log(JSON.stringify(args));
16syncBuiltinESMExports();
17`;
18 const fixture = `
19import { spawn } from "node:child_process";
20import { join } from "node:path";
21spawn(join("sdk with spaces", "emulator", "Emulator.exe"), ["-avd", "Pixel"], {
22 detached: true, stdio: "ignore", env: { TEST: "preserved" }
23});
24spawn("ffmpeg", ["-encoders"], { detached: true, stdio: "pipe" });
25spawn("emulator.exe", { detached: true, cwd: "sdk" });
26console.log(JSON.stringify(process.argv.slice(1)));
27`;
28 const args = deviceHubNodeArgs("unused-entry.mjs", "win32");
29 const { stdout } = await exec(
30 process.execPath,
31 [
32 "--import",
33 `data:text/javascript,${encodeURIComponent(capture)}`,
34 ...args.slice(0, -1),
35 "--input-type=module",
36 "-e",
37 fixture,
38 "--",
39 "--port",
40 "12345",
41 ],
42 { encoding: "utf8", windowsHide: true },
43 );
44 const [emulator, ffmpeg, withoutArgs, argv] = stdout
45 .trim()
46 .split(/\r?\n/)
47 .map((line) => JSON.parse(line));
48 expect(emulator.slice(1)).toEqual([
49 ["-avd", "Pixel"],
50 { detached: false, stdio: "ignore", env: { TEST: "preserved" }, windowsHide: true },
51 ]);
52 expect(ffmpeg).toEqual(["ffmpeg", ["-encoders"], { detached: true, stdio: "pipe" }]);
53 expect(withoutArgs).toEqual([
54 "emulator.exe",
55 { detached: false, cwd: "sdk", windowsHide: true },
56 ]);
57 expect(argv).toEqual(["--port", "12345"]);
58 });
59});