|
7 | 7 | * and runs `auth whoami` against the mock." |
8 | 8 | */ |
9 | 9 |
|
10 | | -import { execFileSync, spawn } from 'node:child_process'; |
11 | | -import { existsSync, mkdtempSync, statSync } from 'node:fs'; |
| 10 | +import { spawn } from 'node:child_process'; |
| 11 | +import { execNpm } from './helpers/execNpm.js'; |
| 12 | +import { existsSync, mkdtempSync, statSync, unlinkSync } from 'node:fs'; |
12 | 13 | import type { IncomingMessage, Server, ServerResponse } from 'node:http'; |
13 | 14 | import { createServer } from 'node:http'; |
14 | 15 | import { tmpdir } from 'node:os'; |
@@ -37,7 +38,7 @@ beforeAll(async () => { |
37 | 38 | // existsSync skip we used to do here let `dist` rot under |
38 | 39 | // refactors and gave false-green on `project list` once |
39 | 40 | // already. |
40 | | - execFileSync('npm', ['run', 'build'], { cwd: REPO_ROOT, stdio: 'pipe' }); |
| 41 | + execNpm(['run', 'build'], { cwd: REPO_ROOT, stdio: 'pipe' }); |
41 | 42 | server = createServer((req: IncomingMessage, res: ServerResponse) => { |
42 | 43 | const url = req.url ?? '/'; |
43 | 44 | if (url.startsWith('/api/cli/v1/projects/')) { |
@@ -356,13 +357,18 @@ interface SpawnResult { |
356 | 357 | stderr: string; |
357 | 358 | } |
358 | 359 |
|
| 360 | +function isolatedHomeEnv(): Record<string, string> { |
| 361 | + // Windows `os.homedir()` reads USERPROFILE, not HOME. |
| 362 | + return { HOME: tmpHome, USERPROFILE: tmpHome }; |
| 363 | +} |
| 364 | + |
359 | 365 | function runCli(args: string[], envOverrides: Record<string, string> = {}): Promise<SpawnResult> { |
360 | 366 | return new Promise((resolveResult, rejectResult) => { |
361 | 367 | const child = spawn('node', [BIN_PATH, ...args], { |
362 | 368 | cwd: REPO_ROOT, |
363 | 369 | env: { |
364 | 370 | ...process.env, |
365 | | - HOME: tmpHome, |
| 371 | + ...isolatedHomeEnv(), |
366 | 372 | TESTSPRITE_API_KEY: undefined, |
367 | 373 | TESTSPRITE_API_URL: undefined, |
368 | 374 | ...envOverrides, |
@@ -803,7 +809,9 @@ describe('setup --from-env subprocess', () => { |
803 | 809 | expect(result.exitCode).toBe(0); |
804 | 810 | const credentialsPath = join(tmpHome, '.testsprite', 'credentials'); |
805 | 811 | expect(existsSync(credentialsPath)).toBe(true); |
806 | | - expect(statSync(credentialsPath).mode & 0o777).toBe(0o600); |
| 812 | + if (process.platform !== 'win32') { |
| 813 | + expect(statSync(credentialsPath).mode & 0o777).toBe(0o600); |
| 814 | + } |
807 | 815 | }, 30_000); |
808 | 816 |
|
809 | 817 | it('exits 5 with VALIDATION_ERROR when --from-env is set without TESTSPRITE_API_KEY', async () => { |
@@ -934,7 +942,7 @@ describe('--dry-run subprocess smoke', () => { |
934 | 942 | // skipped the prompt. |
935 | 943 | const credPath = join(tmpHome, '.testsprite', 'credentials'); |
936 | 944 | // Make sure any previous test didn't leave one behind. |
937 | | - if (existsSync(credPath)) execFileSync('rm', [credPath]); |
| 945 | + if (existsSync(credPath)) unlinkSync(credPath); |
938 | 946 | const result = await runCli(['setup', '--dry-run', '--no-agent', '--output', 'json']); |
939 | 947 | expect(result.exitCode).toBe(0); |
940 | 948 | expect(existsSync(credPath)).toBe(false); |
|
0 commit comments