mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-08-31 02:41:44 +00:00
Merge 89205665b1 into 3337cc8990
This commit is contained in:
@@ -355,6 +355,11 @@ describe("background preview lifecycle", () => {
|
||||
|
||||
expect(result).toMatchObject({ type: "started", port: 3210, pid: 4321 });
|
||||
expect(unref).toHaveBeenCalledOnce();
|
||||
expect(spawn).toHaveBeenCalledWith(
|
||||
"/usr/bin/node",
|
||||
expect.any(Array),
|
||||
expect.objectContaining({ detached: true, windowsHide: true }),
|
||||
);
|
||||
expect(existsSync(previewSessionPath(projectDir, stateHome))).toBe(true);
|
||||
});
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ type SpawnPreview = (
|
||||
detached: boolean;
|
||||
stdio: ["ignore", number, number];
|
||||
env: NodeJS.ProcessEnv;
|
||||
windowsHide: boolean;
|
||||
},
|
||||
) => SpawnResult;
|
||||
|
||||
@@ -219,6 +220,7 @@ function spawnDetachedPreview(
|
||||
detached: true,
|
||||
stdio: ["ignore", logFd, logFd],
|
||||
env: process.env,
|
||||
windowsHide: true,
|
||||
},
|
||||
);
|
||||
} finally {
|
||||
|
||||
@@ -140,13 +140,14 @@ describe("telemetry queue delivery", () => {
|
||||
const [execPath, args, opts] = spawnMock.mock.calls[0] as unknown as [
|
||||
string,
|
||||
string[],
|
||||
{ detached: boolean },
|
||||
{ detached: boolean; windowsHide?: boolean },
|
||||
];
|
||||
expect(execPath).toBe(process.execPath);
|
||||
expect(args[0]).toBe("-e");
|
||||
expect(args[1]).toContain("render_complete");
|
||||
expect(args[1]).toMatch(/[0-9a-f-]{36}/); // event uuid rides along
|
||||
expect(opts.detached).toBe(true);
|
||||
expect(opts.windowsHide).toBe(true);
|
||||
|
||||
// Queue handed to the child — nothing left for a regular flush.
|
||||
const fetchMock = vi.fn(() => Promise.resolve(new Response("")));
|
||||
|
||||
@@ -155,7 +155,7 @@ export function flushSync(): void {
|
||||
"-e",
|
||||
`fetch(${JSON.stringify(`${POSTHOG_HOST}/batch/`)},{method:"POST",headers:{"Content-Type":"application/json"},body:${JSON.stringify(payload)},signal:AbortSignal.timeout(${FLUSH_TIMEOUT_MS})}).catch(()=>{})`,
|
||||
],
|
||||
{ detached: true, stdio: "ignore" },
|
||||
{ detached: true, stdio: "ignore", windowsHide: true },
|
||||
);
|
||||
// Let the parent exit without waiting for the child
|
||||
child.unref();
|
||||
|
||||
@@ -1,10 +1,32 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
|
||||
const spawnMock = vi.hoisted(() =>
|
||||
vi.fn(() => ({
|
||||
on: vi.fn(),
|
||||
unref: vi.fn(),
|
||||
})),
|
||||
);
|
||||
vi.mock("node:child_process", () => ({ spawn: spawnMock }));
|
||||
|
||||
import {
|
||||
buildBrowserArgs,
|
||||
openBrowser,
|
||||
parseRemoteDebuggingPort,
|
||||
validateRemoteDebuggingPortDeps,
|
||||
} from "./openBrowser.js";
|
||||
|
||||
describe("openBrowser", () => {
|
||||
it("hides the console window when spawning a detached browser", () => {
|
||||
openBrowser("http://localhost:3002", { browserPath: "C:\\Browser\\browser.exe" });
|
||||
|
||||
expect(spawnMock).toHaveBeenCalledWith(
|
||||
"C:\\Browser\\browser.exe",
|
||||
["http://localhost:3002"],
|
||||
expect.objectContaining({ detached: true, windowsHide: true }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildBrowserArgs", () => {
|
||||
it("returns only the URL when no options are given", () => {
|
||||
expect(buildBrowserArgs("http://localhost:3002", {})).toEqual(["http://localhost:3002"]);
|
||||
|
||||
@@ -81,6 +81,7 @@ export function openBrowser(url: string, options: OpenBrowserOptions = {}): void
|
||||
const child = spawn(options.browserPath, args, {
|
||||
detached: true,
|
||||
stdio: "ignore",
|
||||
windowsHide: true,
|
||||
});
|
||||
child.on("error", () => {});
|
||||
child.unref();
|
||||
|
||||
Reference in New Issue
Block a user