Public: anyone can read this; the crew can change it.

test/explore-rank.test.ts throws no unhandled error: every run of the file ends with each test named, pass or fail #5670

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/5667-test-explore-rank-test-ts-throws-no-unha → main 2 commits fork 1 thread · 1 unresolved

  • Merged. scout/5667-test-explore-rank-test-ts-throws-no-unha was merged into main as 1978810.

Review

Sign in to review this change.
1 file changed +15 −3
test/explore-rank.test.ts +15 −3
@@ -22,7 +22,13 @@ let app: App;
2222 let owner: User;
2323 const DAY = 86_400_000;
2424
25 beforeAll(async () => {
25 // The setup is one promise the teardown waits for: when a hook gives up on a
26 // slow machine, the loop still running must not write into a closed database
27 // and escape every test as an unhandled error (#5667).
28 let setup: Promise<void> = Promise.resolve();
29 let stopped = false;
30
31 async function seed(): Promise<void> {
2632 dataDir = await mkdtemp(join(tmpdir(), "forge-explore-rank-"));
2733 app = createApp({ dataDir, port: 0 });
2834 const made = await createUser(app.db, {
@@ -37,7 +43,7 @@ beforeAll(async () => {
3743 promote(app.db, made.value);
3844 owner = made.value;
3945 const now = Date.now();
40 for (let i = 0; i < 500; i++) {
46 for (let i = 0; i < 500 && !stopped; i++) {
4147 const repo = await createRepo(app, owner, {
4248 name: `app-${i}`,
4349 visibility: i === 7 ? "private" : "public",
@@ -77,9 +83,15 @@ beforeAll(async () => {
7783 new Date(now - (i % 6) * DAY).toISOString(),
7884 );
7985 }
86 }
87 beforeAll(() => {
88 setup = seed();
89 return setup;
8090 }, 300_000);
8191 afterAll(async () => {
82 app.close();
92 stopped = true;
outdated

This await runs under the default 5 s afterAll timeout. Pass a long timeout as the second argument, and/or stop the loop with a flag so it ends promptly.

93 await setup.catch(() => {});
94 if (app !== undefined) app.close();
8395 await rm(dataDir, { recursive: true, force: true });
8496 });
8597

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs