|
1 | | -import { execFileSync, spawnSync } from "node:child_process"; |
2 | 1 | import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; |
3 | 2 | import { tmpdir } from "node:os"; |
4 | 3 | import { join } from "node:path"; |
5 | 4 | import { describe, expect, it } from "vitest"; |
| 5 | +import { execNodeEvalSync, spawnNodeEvalSync } from "../../src/test-utils/node-process.js"; |
6 | 6 |
|
7 | 7 | const WRAPPERS = { |
8 | 8 | linux: "scripts/e2e/parallels-linux-smoke.sh", |
@@ -46,10 +46,7 @@ function countNonEmptyLines(value: string): number { |
46 | 46 | } |
47 | 47 |
|
48 | 48 | function runTsEval(source: string, env: Record<string, string> = {}) { |
49 | | - return execFileSync("node", ["--import", "tsx", "--input-type=module", "--eval", source], { |
50 | | - encoding: "utf8", |
51 | | - env: { ...process.env, ...env }, |
52 | | - }); |
| 49 | + return execNodeEvalSync(source, { env: { ...process.env, ...env }, imports: ["tsx"] }); |
53 | 50 | } |
54 | 51 |
|
55 | 52 | function resolveProviderAuth( |
@@ -313,32 +310,18 @@ console.log(JSON.stringify(result)); |
313 | 310 | }); |
314 | 311 |
|
315 | 312 | it("rejects invalid providers and missing keys before touching guests", () => { |
316 | | - const invalidProvider = spawnSync( |
317 | | - "node", |
318 | | - [ |
319 | | - "--import", |
320 | | - "tsx", |
321 | | - "--input-type=module", |
322 | | - "--eval", |
323 | | - `import { parseProvider } from "./${TS_PATHS.common}"; parseProvider("bogus");`, |
324 | | - ], |
325 | | - { encoding: "utf8", env: process.env }, |
| 313 | + const invalidProvider = spawnNodeEvalSync( |
| 314 | + `import { parseProvider } from "./${TS_PATHS.common}"; parseProvider("bogus");`, |
| 315 | + { env: process.env, imports: ["tsx"] }, |
326 | 316 | ); |
327 | 317 | expect(invalidProvider.status).toBe(1); |
328 | 318 | expect(invalidProvider.stderr).toContain("invalid --provider: bogus"); |
329 | 319 |
|
330 | | - const missingKey = spawnSync( |
331 | | - "node", |
332 | | - [ |
333 | | - "--import", |
334 | | - "tsx", |
335 | | - "--input-type=module", |
336 | | - "--eval", |
337 | | - `import { resolveProviderAuth } from "./${TS_PATHS.common}"; resolveProviderAuth({ provider: "openai", apiKeyEnv: "PARALLELS_TEST_MISSING_KEY" });`, |
338 | | - ], |
| 320 | + const missingKey = spawnNodeEvalSync( |
| 321 | + `import { resolveProviderAuth } from "./${TS_PATHS.common}"; resolveProviderAuth({ provider: "openai", apiKeyEnv: "PARALLELS_TEST_MISSING_KEY" });`, |
339 | 322 | { |
340 | | - encoding: "utf8", |
341 | 323 | env: { ...process.env, PARALLELS_TEST_MISSING_KEY: "" }, |
| 324 | + imports: ["tsx"], |
342 | 325 | }, |
343 | 326 | ); |
344 | 327 | expect(missingKey.status).toBe(1); |
|
0 commit comments