|
1 | 1 | // Test Force tests cover test force script behavior. |
| 2 | +import { spawnSync } from "node:child_process"; |
2 | 3 | import { describe, expect, it } from "vitest"; |
3 | | -import { testForceTesting } from "../../scripts/test-force.js"; |
| 4 | + |
| 5 | +function runTestForce(...args: string[]) { |
| 6 | + return spawnSync(process.execPath, ["--import", "tsx", "scripts/test-force.ts", ...args], { |
| 7 | + cwd: process.cwd(), |
| 8 | + encoding: "utf8", |
| 9 | + }); |
| 10 | +} |
4 | 11 |
|
5 | 12 | describe("scripts/test-force.ts", () => { |
6 | 13 | it("prints help without clearing ports or running tests", () => { |
7 | | - const args = testForceTesting.parseArgs(["--help", "--bogus"]); |
| 14 | + const result = runTestForce("--help"); |
8 | 15 |
|
9 | | - expect(args).toEqual({ help: true }); |
10 | | - expect(testForceTesting.usage()).toContain("Usage: node --import tsx scripts/test-force.ts"); |
11 | | - expect(testForceTesting.usage()).not.toContain("test:force - clearing gateway"); |
12 | | - expect(testForceTesting.usage()).not.toContain("running pnpm test"); |
| 16 | + expect(result.status).toBe(0); |
| 17 | + expect(result.stderr).toBe(""); |
| 18 | + expect(result.stdout).toContain("Usage: node --import tsx scripts/test-force.ts"); |
| 19 | + expect(result.stdout).not.toContain("test:force - clearing gateway"); |
| 20 | + expect(result.stdout).not.toContain("running pnpm test"); |
13 | 21 | }); |
14 | 22 |
|
15 | 23 | it("rejects unknown arguments before clearing ports or running tests", () => { |
16 | | - expect(() => testForceTesting.parseArgs(["--bogus"])).toThrow( |
17 | | - /unknown argument: --bogus[\s\S]*Usage: node --import tsx scripts\/test-force\.ts/u, |
18 | | - ); |
19 | | - expect(() => testForceTesting.parseArgs(["bogus"])).toThrow( |
20 | | - /unknown argument: bogus[\s\S]*Usage: node --import tsx scripts\/test-force\.ts/u, |
21 | | - ); |
22 | | - expect(() => testForceTesting.parseArgs(["bogus", "--help"])).toThrow( |
23 | | - /unknown argument: bogus[\s\S]*Usage: node --import tsx scripts\/test-force\.ts/u, |
24 | | - ); |
| 24 | + const result = runTestForce("--bogus"); |
| 25 | + |
| 26 | + expect(result.status).toBe(2); |
| 27 | + expect(result.stderr).toContain("unknown argument: --bogus"); |
| 28 | + expect(result.stderr).toContain("Usage: node --import tsx scripts/test-force.ts"); |
| 29 | + expect(result.stdout).not.toContain("test:force - clearing gateway"); |
| 30 | + expect(result.stdout).not.toContain("running pnpm test"); |
25 | 31 | }); |
26 | 32 | }); |
0 commit comments