



















@@ -5,12 +5,14 @@ import { setTimeout as sleep } from "node:timers/promises";
55import { afterEach, describe, expect, it } from "vitest";
66import { validateQaEvidenceSummaryJson } from "./evidence-summary.js";
77import { readQaScenarioById, type QaSeedScenarioWithSource } from "./scenario-catalog.js";
8+import { createTempDirHarness } from "./temp-dir.test-helper.js";
89import {
910runQaTestFileScenarios,
1011type QaScenarioCommandExecution,
1112} from "./test-file-scenario-runner.js";
12131314const tempRoots: string[] = [];
15+const { cleanup: cleanupTempDirs, makeTempDir } = createTempDirHarness();
14161517function isProcessRunning(pid: number) {
1618try {
@@ -88,9 +90,10 @@ async function makeTempRepo(prefix: string) {
88908991describe("qa test file scenario runner", () => {
9092afterEach(async () => {
91-await Promise.all(
92-tempRoots.splice(0).map((root) => fs.rm(root, { recursive: true, force: true })),
93-);
93+await Promise.all([
94+cleanupTempDirs(),
95+ ...tempRoots.splice(0).map((root) => fs.rm(root, { recursive: true, force: true })),
96+]);
9497});
95989699it("runs Playwright scenarios with the repo UI e2e command and writes Playwright evidence", async () => {
@@ -378,11 +381,10 @@ describe("qa test file scenario runner", () => {
378381}
379382380383const repoRoot = process.cwd();
381-const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "qa-script-timeout-"));
382-tempRoots.push(tempRoot);
384+const tempRoot = await makeTempDir("qa-script-timeout-");
383385const scriptPath = path.join(tempRoot, "hanging-producer.ts");
384386const descendantPidPath = path.join(tempRoot, "descendant.pid");
385-let descendantPid = 0;
387+let descendantPid: number | undefined;
386388try {
387389const descendantScript = [
388390"process.on('SIGTERM', () => {});",
@@ -418,16 +420,15 @@ describe("qa test file scenario runner", () => {
418420expect(result.results[0]?.failureMessage).toMatch(/timed out after 500ms/u);
419421await waitForDead(descendantPid, 2_000);
420422} finally {
421-if (descendantPid && isProcessRunning(descendantPid)) {
423+if (descendantPid !== undefined && isProcessRunning(descendantPid)) {
422424process.kill(descendantPid, "SIGKILL");
423425}
424426}
425427});
426428427429it("fails script scenarios that exit cleanly after timeout termination", async () => {
428430const repoRoot = process.cwd();
429-const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "qa-script-timeout-clean-exit-"));
430-tempRoots.push(tempRoot);
431+const tempRoot = await makeTempDir("qa-script-timeout-clean-exit-");
431432const scriptPath = path.join(tempRoot, "clean-exit-after-timeout.ts");
432433await fs.writeFile(
433434scriptPath,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。