Skip to content

Commit 7b77bf6

Browse files
committed
fix(e2e): run subprocess harness and proxy probe via tsx
Node's strip-only TypeScript mode cannot execute workspace source that uses parameter properties. Use the monorepo tsx binary for runNodeMain and the proxy e2e probe (.mts for top-level await).
1 parent 6e5ecf8 commit 7b77bf6

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

packages/e2e/src/run-subprocess.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { execFile } from "child_process";
2+
import { join } from "path";
23
import { promisify } from "util";
4+
import { monorepoRoot } from "./monorepo-root.ts";
35

46
const execFileAsync = promisify(execFile);
57

@@ -9,14 +11,21 @@ export interface RunCliResult {
911
exitCode: number;
1012
}
1113

12-
/** 子进程执行指定 main.ts 入口 */
14+
/** monorepo 根目录下的 tsx 可执行文件 */
15+
export function resolveTsxBin(): string {
16+
const root = monorepoRoot();
17+
const name = process.platform === "win32" ? "tsx.cmd" : "tsx";
18+
return join(root, "node_modules", ".bin", name);
19+
}
20+
21+
/** 子进程通过 tsx 执行指定 main.ts 入口 */
1322
export async function runNodeMain(
1423
mainTs: string,
1524
args: string[],
1625
options: { cwd: string; env?: NodeJS.ProcessEnv } = { cwd: process.cwd() },
1726
): Promise<RunCliResult> {
1827
try {
19-
const { stdout, stderr } = await execFileAsync("node", [mainTs, ...args], {
28+
const { stdout, stderr } = await execFileAsync(resolveTsxBin(), [mainTs, ...args], {
2029
cwd: options.cwd,
2130
encoding: "utf8",
2231
maxBuffer: 32 * 1024 * 1024,

packages/runtime/tests/proxy.e2e.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { dirname, join } from "path";
77
import { fileURLToPath } from "url";
88
import { promisify } from "util";
99
import { afterAll, beforeAll, describe, expect, test } from "vite-plus/test";
10+
import { resolveTsxBin } from "e2e/runner";
1011

1112
const execFileAsync = promisify(execFile);
1213

@@ -46,7 +47,7 @@ beforeAll(async () => {
4647
proxyUrl = `http://127.0.0.1:${(proxy.address() as AddressInfo).port}`;
4748

4849
scriptDir = mkdtempSync(join(tmpdir(), "bl-proxy-e2e-"));
49-
scriptPath = join(scriptDir, "probe.ts");
50+
scriptPath = join(scriptDir, "probe.mts");
5051
writeFileSync(scriptPath, PROBE_SCRIPT);
5152
});
5253

@@ -68,7 +69,7 @@ async function runProbe(
6869
envOverrides: NodeJS.ProcessEnv,
6970
): Promise<{ exitCode: number; stderr: string }> {
7071
try {
71-
await execFileAsync("node", [scriptPath], {
72+
await execFileAsync(resolveTsxBin(), [scriptPath], {
7273
cwd: runtimePackageRoot,
7374
encoding: "utf8",
7475
env: { ...process.env, NODE_NO_WARNINGS: "1", ...PROXY_ENV_CLEARED, ...envOverrides },

0 commit comments

Comments
 (0)