Skip to content

test: wait for the confetti import before each run-page test ends - #105

Merged
keyurgolani merged 1 commit into
nextfrom
test/confetti-import-flake
Oct 21, 2026
Merged

keyurgolani merged 1 commit into
nextfrom
test/confetti-import-flake

Conversation

@keyurgolani

@keyurgolani keyurgolani commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

Implements CHECKMATE-09.1 · slice 0 (follow-up)
Refs #53

What changed

The run-page test waits for pending dynamic imports at the start of its afterEach (await vi.dynamicImportSettled()). No product change.

Why

A confirmed toggle starts import('@/lib/confetti') without awaiting it (checklist-detail-client.tsx#L273-L277), and under load the third test's import was still loading when the fourth test started its own. When one file has two imports of the same vi.mocked module pending at once, vitest gives the second one the real module (moduleMocker.ts#L468-L487), so the real canvas-confetti ran and threw on jsdom's null canvas context after all four tests had passed.

Verification

Both batches ran six copies of the file in parallel loops, with npm run test:backend looping beside them and 18 busy-loop threads, on a shared 18-core machine already near load average 55. Load average ran 59 to 96.

  • Before: 5 of 180 runs exited 1 with all four tests passing, each on the canvas-confetti clearRect TypeError.
  • After: 0 of 150 runs failed or reported an unhandled error.

With a throwaway patch that delays vitest's fetch of that module by 300 ms and holds the last test open for a second, 3 of 3 runs failed before the change and 0 of 3 after.

Gate:

  • npx eslint on the changed file exits 0, with no eslint-disable added.
  • npm run lint reports 37 errors and 48 warnings, same as origin/next.
  • npx tsc --noEmit reports 0 errors, same as origin/next.
  • npm test passes, 43 files and 798 tests.
  • npm run build passes with both PocketBase URLs at http://127.0.0.1:9.

Decisions and owner steps

Only the run page fires confetti (grep -rn "lib/confetti" src), so no other test needed the wait. The wait alone held, so canvas-confetti isn't mocked as well. No owner steps.

Summary by Sourcery

Ensure run-page tests wait for pending dynamic imports before completing each test.

Bug Fixes:

  • Prevent flaky run-page tests caused by pending confetti dynamic imports leaking into subsequent tests.

Tests:

  • Ensure dynamic imports settle before run-page test cleanup completes.

A confirmed toggle on the run page starts import('@/lib/confetti') without
awaiting it. When that import was still loading as the next test started its
own, vitest gave the second import the real module, and canvas-confetti threw
on jsdom's null canvas context after every test had passed. Each test now
waits for pending dynamic imports before it ends.

Implements CHECKMATE-09.1 · slice 0 follow-up
Refs #53
@sourcery-ai

sourcery-ai Bot commented Oct 21, 2026

Copy link
Copy Markdown

Sorry @keyurgolani, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 6 days and 5 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 21, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR fixes an intermittent run-page test failure by waiting for fire-and-forget confetti imports to settle during afterEach, preventing Vitest from resolving a concurrent import to the real canvas-confetti module in jsdom; no product code changes are made.

Sequence diagram for settling confetti imports between run-page tests

sequenceDiagram
    participant Test as Run-page test
    participant Cleanup as afterEach
    participant Vitest
    participant Confetti as lib/confetti
    participant Canvas as jsdom canvas

    Test->>Confetti: import('@/lib/confetti')
    Test-->>Cleanup: test completes
    Cleanup->>Vitest: dynamicImportSettled()
    Vitest-->>Cleanup: pending imports settled
    Cleanup->>Cleanup: cleanup()
    Cleanup->>Vitest: restore mocks and globals
    Cleanup-->>Test: next test starts safely
    Confetti->>Canvas: canvas-confetti uses mocked module
Loading

File-Level Changes

Change Details Files
Make run-page test teardown await pending dynamic imports before releasing test state.
  • Convert the shared afterEach hook to async.
  • Call vi.dynamicImportSettled() before cleanup and mock restoration.
  • Document the race between the fire-and-forget confetti import and the next test's mocked import.
src/app/(dashboard)/checklists/[id]/checklist-detail-client.test.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@keyurgolani
keyurgolani merged commit 4aa7315 into next Oct 21, 2026
10 checks passed
@keyurgolani
keyurgolani deleted the test/confetti-import-flake branch October 21, 2026 02:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant