Public: anyone can read this; the crew can change it.
test/forks.test.ts runs under 10 s #3597
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/3579-test-forks-test-ts-runs-under-10-s → main 2 commits fork 1 thread · 1 unresolved
3 files
changed +38
−1
scripts/test-shards.ts +6
| @@ -297,6 +297,12 @@ if (tier === "fast") { | ||
| 297 | 297 | ); |
| 298 | 298 | for (const file of plan.files) |
| 299 | 299 | console.log(` ${file}: ${plan.why.get(file)}`); |
| 300 | // A diff no test reaches (a timing table, a doc) is judged by the | |
| 301 | // type check alone: green, not a usage error. | |
| 302 | if (plan.files.length === 0) { | |
| 303 | console.log("test-shards: the change reaches no tests; nothing to run"); | |
| 304 | process.exit(0); | |
| 305 | } | |
| 300 | 306 | files = plan.files; |
| 301 | 307 | } |
| 302 | 308 |
scripts/test-times.json +1 −1
| @@ -37,7 +37,7 @@ | ||
| 37 | 37 | "test/feed.test.ts": 8.3, |
| 38 | 38 | "test/forge-cloudflare.test.ts": 0.1, |
| 39 | 39 | "test/fork-flow.test.ts": 48.4, |
| 40 | "test/forks.test.ts": 28.9, | |
| 40 | "test/forks.test.ts": 1.5, | |
| 41 | 41 | "test/git-trust.test.ts": 0.3, |
| 42 | 42 | "test/helpers.test.ts": 0.7, |
| 43 | 43 | "test/landing.test.ts": 9.4, |
test/shards.test.ts +31
| @@ -667,6 +667,37 @@ describe("the gate audit before any shard", () => { | ||
| 667 | 667 | expect(got.out).toContain("for 1 changed"); |
| 668 | 668 | expect(got.out).toContain(" test/zz-new.test.ts: changed\n"); |
| 669 | 669 | }, 30_000); |
| 670 | ||
| 671 | test("a pull no test reaches is green with nothing to run, not a usage error (#3579)", async () => { | |
| 672 | const dir = mkdtempSync(join(tmpdir(), "forge-audit-")); | |
| 673 | mkdirSync(join(dir, "test")); | |
| 674 | for (const file of listed) writeFileSync(join(dir, file), ""); | |
| 675 | writeFileSync(join(dir, "impact.json"), JSON.stringify(Object.fromEntries(listed.map((f) => [f, []])))); | |
| 676 | expect(git(dir, "init", "-q")).toBe(0); | |
| 677 | expect(git(dir, "add", "-A")).toBe(0); | |
| 678 | expect(git(dir, "commit", "-qm", "base")).toBe(0); | |
| 679 | mkdirSync(join(dir, "scripts")); | |
| 680 | writeFileSync(join(dir, "scripts", "test-times.json"), "{}\n"); | |
| 681 | expect(git(dir, "add", "-A")).toBe(0); | |
| 682 | expect(git(dir, "commit", "-qm", "a table only")).toBe(0); | |
| 683 | const child = Bun.spawn(["bun", script, "--tier", "fast", "--diff", "HEAD~1..HEAD"], { | |
| 684 | cwd: dir, | |
| 685 | env: { ...process.env, FORGE_CHECK_IMPACT: "impact.json" }, | |
| 686 | stdin: "ignore", | |
| 687 | stdout: "pipe", | |
| 688 | stderr: "pipe", | |
| 689 | }); | |
| 690 | const [out, err] = await Promise.all([ | |
| 691 | new Response(child.stdout).text(), | |
| 692 | new Response(child.stderr).text(), | |
| 693 | ]); | |
| 694 | const code = await child.exited; | |
| 695 | rmSync(dir, { recursive: true, force: true }); | |
| 696 | expect(out).toContain(`0 of ${gateFiles().length} files for 1 changed`); | |
| 697 | expect(out).toContain("test-shards: the change reaches no tests; nothing to run"); | |
| 698 | expect(err).not.toContain("name the test files"); | |
| 699 | expect(code).toBe(0); | |
| 700 | }, 30_000); | |
| 670 | 701 | }); |
| 671 | 702 | |
| 672 | 703 | describe("the gate audit alone, first in the check", () => { |
new above
offline
Exit 0 here is correct for a table or doc-only diff. Beware that a mistyped --diff range with zero changed files also lands here silently; consider printing the changed count (already in the line above, so fine) or exiting non-zero when changed.length is 0.