Skip to content

test(web): run isolated web suite directly#1848

Merged
tyler-dane merged 9 commits into
mainfrom
chore/web-test-cleanup
Jun 2, 2026
Merged

test(web): run isolated web suite directly#1848
tyler-dane merged 9 commits into
mainfrom
chore/web-test-cleanup

Conversation

@tyler-dane
Copy link
Copy Markdown
Contributor

@tyler-dane tyler-dane commented Jun 2, 2026

Summary

Reduces web unit test runs from ~4min to under 1 minute.

This replaces the interim batched web test runner with the intended endpoint: bun run test:web now runs bun test --cwd packages/web directly, and the shared test dispatcher no longer walks or chunks web test files.

The branch keeps the previous batching commit as history, but the latest commit removes that workaround and fixes the underlying isolation leaks that forced batching/process boundaries in the first place.

What changed

  • Removed web-specific batching from packages/scripts/src/testing/run.ts.
  • Changed package.json so test:web is a direct Bun test command.
  • Added render-with-store for web tests that should use real Redux providers instead of mocking store hooks.
  • Reworked leaking web tests away from broad mock.module usage for shared modules and UI primitives.
  • Added small dependency factories for hard-to-isolate hooks/utilities instead of mocking production modules process-wide.
  • Tightened web preload cleanup for DOM/storage/MSW/browser state and sanitized the JSDOM-hostile datepicker :has(...) styled-components rule without deleting unrelated styles.
  • Updated the testing playbook with web isolation rules and direct-suite acceptance criteria.

Why the interim batching approach was a smell

Batching made the suite faster than one-file-per-process execution, but it still encoded test isolation into packages/scripts/src/testing/run.ts instead of into the tests themselves. That meant:

  • the runner knew too much about web test file layout;
  • WEB_TEST_BATCH_SIZE became a hidden compatibility contract;
  • top-level mock.module leaks still depended on file order and process boundaries;
  • broad child/store/session mocks could silently change later tests in the same Bun process;
  • the desired command, bun test --cwd packages/web, still could not be trusted.

The real fix is to keep tests independent enough that Bun can run the package suite in one direct invocation.

Follow-up plan

The suite now meets the desired endpoint, but the remaining test hygiene work should continue in normal feature work:

  1. Prefer real providers and renderWithStore over mocking Redux hooks or @web/store.
  2. Avoid top-level mock.module for shared UI primitives, session hooks, and utility modules.
  3. Use dependency factories only where the dependency is genuinely hard to control through providers or public APIs.
  4. Restore any replaced globals in teardown.
  5. Treat bun test --cwd packages/web as the acceptance check for web isolation, not just focused file runs.

Verification

  • bun test --cwd packages/web passes: 1029 tests.
  • bun run test:web passes: 1029 tests.
  • bun run type-check:web-tests passes.
  • bun run type-check passes.
  • bun lint passes.
  • bun run test:scripts passes: 57 tests.

@tyler-dane tyler-dane changed the title test(web): checkpoint web test cleanup test(web): run isolated web suite directly Jun 2, 2026
@tyler-dane tyler-dane force-pushed the chore/web-test-cleanup branch 8 times, most recently from 0d25fba to fa28e11 Compare June 2, 2026 16:13
- Override getBoundingClientRect on BOTH HTMLElement.prototype and
  window.HTMLElement.prototype since JSDOM may use a different
  HTMLElement internally than globalThis
- Use hardcoded test rects based on testid for consistent values
- Remove intermediate ref callbacks, use hook refs directly
- Move ResizeObserver mock setup to beforeEach for consistent timing
- Replace waitFor with direct assertions after explicit timeout
- Reset motion state in beforeEach/afterEach

The tests were failing in CI because:
1. JSDOM creates its own HTMLElement class assigned to window.HTMLElement
2. Elements created by JSDOM use window.HTMLElement.prototype
3. Only overriding globalThis.HTMLElement.prototype wasn't sufficient
4. Must override both prototypes to ensure the mock is used

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@tyler-dane tyler-dane force-pushed the chore/web-test-cleanup branch 3 times, most recently from 49063c2 to 1d35337 Compare June 2, 2026 16:38
Use the canonical test pattern with renderHook and mock elements rather
than rendering full components with prototype-level getBoundingClientRect
overrides. This approach is consistent with useCalendarGridLayout tests
and avoids CI-specific prototype override issues.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@tyler-dane tyler-dane force-pushed the chore/web-test-cleanup branch from 1d35337 to b24b3fa Compare June 2, 2026 16:41
tyler-dane and others added 5 commits June 2, 2026 11:43
The useGridLayout hook is a thin wrapper around useCalendarGridLayout
that passes DAYS_IN_VIEW=7 and isWeekInteractionMotionActive. All
functionality is already covered by useCalendarGridLayout.test.tsx
which tests the same 7-day layout measurements.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The createPlannerSidebar refactor imported the fixed-position shortcut
hint overlay instead of the sidebar modal, which blocked sidebar clicks
in e2e tests and ignored isShortcutsOpen.

Co-authored-by: Cursor <cursoragent@cursor.com>
@tyler-dane tyler-dane marked this pull request as ready for review June 2, 2026 18:03
@tyler-dane tyler-dane merged commit 0be5c93 into main Jun 2, 2026
9 checks passed
@tyler-dane tyler-dane deleted the chore/web-test-cleanup branch June 2, 2026 18:10
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