diff --git a/scripts/ci/stalled-file-reporter.test.mjs b/scripts/ci/stalled-file-reporter.test.mjs index 840cf6d5e6f..ab9e58b70da 100644 --- a/scripts/ci/stalled-file-reporter.test.mjs +++ b/scripts/ci/stalled-file-reporter.test.mjs @@ -3,7 +3,7 @@ import { spawnSync } from "node:child_process"; import { mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; -import { fileURLToPath } from "node:url"; +import { fileURLToPath, pathToFileURL } from "node:url"; import test from "node:test"; import StalledFileReporter, { defaultStallMs, stallAnnotation, stalledFileReporterEnabled, stallLimitMs } from "./stalled-file-reporter.mjs"; @@ -83,9 +83,9 @@ test("a file that never finishes loading is named from the moment it is queued", // The failure this guards: a test awaiting a promise that never settles, with // a test timeout longer than the CI job, holds Vitest until the job is // cancelled and never prints the file's name. -for (const [label, body, step] of [ - ["a test that never settles", 'import { test } from "vitest";\ntest("waits forever", () => new Promise(() => {}), 600_000);\n', 'test "waits forever"'], - ["a top-level await that never settles", 'import { test } from "vitest";\nawait new Promise(() => {});\ntest("never collected", () => {});\n', "loading the file"], +for (const [label, body, steps] of [ + ["a test that never settles", 'import { test } from "vitest";\nimport { writeFileSync } from "node:fs";\ntest("waits forever", () => { writeFileSync(process.env.PAPERCLIP_WATCHDOG_TEST_STARTED, "started"); return new Promise(() => {}); }, 600_000);\n', ['test "waits forever"']], + ["a top-level await that never settles", 'import { test } from "vitest";\nawait new Promise(() => {});\ntest("never collected", () => {});\n', ["loading the file"]], ]) test(`a real Vitest run with ${label} fails fast and names the file`, () => { const directory = realpathSync(mkdtempSync(path.join(tmpdir(), "stalled-file-reporter-"))); try { @@ -93,21 +93,27 @@ for (const [label, body, step] of [ writeFileSync(path.join(directory, "quick.test.mjs"), `import { test } from "vitest"; test("passes", () => {}); `); + const startedMarker = path.join(directory, "started"); + let fixtureReporter = reporterPath; + if (label === "a test that never settles") { + fixtureReporter = path.join(directory, "after-test-start.mjs"); + writeFileSync(fixtureReporter, 'import Base from ' + JSON.stringify(pathToFileURL(reporterPath).href) + ';\nimport { existsSync } from "node:fs";\nexport default class extends Base { check() { if (!existsSync(' + JSON.stringify(startedMarker) + ')) return; super.check(); } }\n'); + } const configFile = path.join(directory, "vitest.config.mjs"); writeFileSync(configFile, `export default ${JSON.stringify({ test: { include: ["*.test.mjs"], - reporters: ["default", [reporterPath, { limitMs: 1500, graceMs: 5000, root: directory }]] } })};`); + reporters: ["default", [fixtureReporter, { limitMs: 1500, graceMs: 5000, root: directory }]] } })};`); const started = Date.now(); const result = spawnSync(process.execPath, [path.join(root, "node_modules/vitest/vitest.mjs"), "run", "--config", configFile, "--root", directory], { cwd: directory, encoding: "utf8", timeout: 60_000, - env: { ...process.env, GITHUB_ACTIONS: "", PAPERCLIP_VITEST_FILE_STALL_MS: "" }, + env: { ...process.env, GITHUB_ACTIONS: "", PAPERCLIP_VITEST_FILE_STALL_MS: "", PAPERCLIP_WATCHDOG_TEST_STARTED: startedMarker }, }); const output = `${result.stdout}\n${result.stderr}`; assert.equal(result.signal, null, `Vitest was still running after 60 s:\n${output}`); assert.notEqual(result.status, 0, output); assert.ok(Date.now() - started < 30_000, `took ${Date.now() - started} ms:\n${output}`); assert.match(output, /::error file=stuck\.test\.mjs,title=Test file stopped making progress::stuck\.test\.mjs made no progress/); - assert.ok(output.includes(`while in: ${step}.`), output); + assert.ok(steps.some(step => output.includes(`while in: ${step}.`)), output); } finally { rmSync(directory, { recursive: true, force: true }); } diff --git a/tests/e2e/planning-mode-visual-verification.spec.ts b/tests/e2e/planning-mode-visual-verification.spec.ts index 785ae5a2b94..309ee89b457 100644 --- a/tests/e2e/planning-mode-visual-verification.spec.ts +++ b/tests/e2e/planning-mode-visual-verification.spec.ts @@ -125,7 +125,7 @@ test("captures planning mode UI for desktop and mobile", async ({ page }) => { const issueIdentifier = issue.identifier ?? issue.id; const issuePath = `/${company.issuePrefix ?? company.id}/issues/${issueIdentifier}`; const companyPrefix = company.issuePrefix ?? company.id; - const issueLinkSelector = `a[href$="/issues/${issueIdentifier}"]`; + const issueRow = page.locator(`[data-issue-row-details="${issue.id}"]`); const setMode = async (mode: "standard" | "planning") => { const patchRes = await page.request.patch(`${baseOrigin}/api/issues/${issue.id}`, { @@ -159,8 +159,8 @@ test("captures planning mode UI for desktop and mobile", async ({ page }) => { }); await page.goto(`/${companyPrefix}/issues`); - await expect(page.locator(issueLinkSelector)).toBeVisible(); - await expect(page.locator(issueLinkSelector)).not.toContainText("Plan mode"); + await expect(issueRow).toBeVisible(); + await expect(issueRow).not.toContainText("Plan mode"); await page.screenshot({ path: `${screenshotDir}/desktop-planning-row-${timestamp}.png`, fullPage: true, @@ -190,8 +190,8 @@ test("captures planning mode UI for desktop and mobile", async ({ page }) => { }); await page.goto(`/${companyPrefix}/issues`); - await expect(page.locator(issueLinkSelector)).toBeVisible(); - await expect(page.locator(issueLinkSelector)).not.toContainText("Plan mode"); + await expect(issueRow).toBeVisible(); + await expect(issueRow).not.toContainText("Plan mode"); await page.screenshot({ path: `${screenshotDir}/mobile-planning-row-${timestamp}.png`, fullPage: true,