|
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/')) { |
@@ -358,13 +359,18 @@ interface SpawnResult { |
358 | 359 | stderr: string; |
359 | 360 | } |
360 | 361 |
|
| 362 | +function isolatedHomeEnv(): Record<string, string> { |
| 363 | + // Windows `os.homedir()` reads USERPROFILE, not HOME. |
| 364 | + return { HOME: tmpHome, USERPROFILE: tmpHome }; |
| 365 | +} |
| 366 | + |
361 | 367 | function runCli(args: string[], envOverrides: Record<string, string> = {}): Promise<SpawnResult> { |
362 | 368 | return new Promise((resolveResult, rejectResult) => { |
363 | 369 | const child = spawn('node', [BIN_PATH, ...args], { |
364 | 370 | cwd: REPO_ROOT, |
365 | 371 | env: { |
366 | 372 | ...process.env, |
367 | | - HOME: tmpHome, |
| 373 | + ...isolatedHomeEnv(), |
368 | 374 | TESTSPRITE_API_KEY: undefined, |
369 | 375 | TESTSPRITE_API_URL: undefined, |
370 | 376 | ...envOverrides, |
@@ -897,7 +903,9 @@ describe('setup --from-env subprocess', () => { |
897 | 903 | expect(result.exitCode).toBe(0); |
898 | 904 | const credentialsPath = join(tmpHome, '.testsprite', 'credentials'); |
899 | 905 | expect(existsSync(credentialsPath)).toBe(true); |
900 | | - expect(statSync(credentialsPath).mode & 0o777).toBe(0o600); |
| 906 | + if (process.platform !== 'win32') { |
| 907 | + expect(statSync(credentialsPath).mode & 0o777).toBe(0o600); |
| 908 | + } |
901 | 909 | }, 30_000); |
902 | 910 |
|
903 | 911 | it('exits 5 with VALIDATION_ERROR when --from-env is set without TESTSPRITE_API_KEY', async () => { |
@@ -1044,7 +1052,7 @@ describe('--dry-run subprocess smoke', () => { |
1044 | 1052 | // skipped the prompt. |
1045 | 1053 | const credPath = join(tmpHome, '.testsprite', 'credentials'); |
1046 | 1054 | // Make sure any previous test didn't leave one behind. |
1047 | | - if (existsSync(credPath)) execFileSync('rm', [credPath]); |
| 1055 | + if (existsSync(credPath)) unlinkSync(credPath); |
1048 | 1056 | const result = await runCli(['setup', '--dry-run', '--no-agent', '--output', 'json']); |
1049 | 1057 | expect(result.exitCode).toBe(0); |
1050 | 1058 | expect(existsSync(credPath)).toBe(false); |
|
0 commit comments