Skip to content

fix(test): the vitest include pointed at a directory that does not exist, so 692 tests never ran - #28

Merged
thinkclay merged 1 commit into
mainfrom
fix/469-vitest-include
Sep 2, 2026
Merged

thinkclay merged 1 commit into
mainfrom
fix/469-vitest-include

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

The mechanism

vitest.config.ts set its include to:

packages/scaffald-ui/src/**/*.{test,spec}.{ts,tsx}

The package has been at packages/ui since it was renamed. root is the workspace root, so that glob resolved against a path that has not existed for months — it matched zero files and vitest exited 0. With passWithNoTests: true in project.json, nx run @scaffald/ui:test reported success while running nothing.

41 test files. 692 tests. None of them ran.

The config's TODO blamed "a double-path esbuild error in the NX executor" for the wrong path. That no longer reproduces — with the include corrected, nx run @scaffald/ui:test --skip-nx-cache passes.

What turning them on surfaced

Six failures, none of them new.

useSidebarState — a real crash

safeLocalStorage() guarded reaching window.localStorage, but not reading or writing through it — and those are the calls that actually throw. Safari private mode, an iframe with third-party cookies blocked, and an exhausted quota all hand back a real Storage object whose getItem/setItem raise SecurityError / QuotaExceededError.

The read sits inside a useState initializer, so the throw propagated out of render and took down every page that mounts a sidebar. Both accesses are now guarded.

useResponsive — stale tests

Written against an older per-instance implementation that read window.innerWidth on every render, so they replaced global.window with a plain object.

The hook was since rewritten to a module-level singleton store — one shared resize listener for the whole tree — which reads document.documentElement.clientWidth (to exclude the scrollbar and agree with CSS media queries) and only re-reads on a resize event.

Against that implementation the mock could never work: the replacement window had no document, and the mocked addEventListener never fired anything. Every width-specific assertion was really asserting against jsdom's width at import time, which is 0.

Rewritten to move the real viewport and dispatch the real event. Several assertions that had been weakened to expect(typeof value).toBe('number') now check the actual value.

Modal — a test that could only pass vacuously

Modal ignores a backdrop click within 200ms of opening, to swallow the stray click that can follow the gesture that opened it. The test pinned Date.now to a single fixed value to clear that window — which guarantees the opposite. openedAtRef is stamped from the same mocked clock at render, so Date.now() - openedAtRef.current is always 0 and the handler always returned early.

Its sibling — asserting onClose is not called when closeOnBackdropPress is false — was passing for that reason rather than the intended one. The clock now advances between opening and clicking.

Result

692 passing, 0 failing.

passWithNoTests is now false, so a glob matching nothing fails loudly. That is the mechanism that let this persist, and it is worth closing along with the symptom.

Refs Scaffald/SaaS#469

…ist, so 692 tests never ran

`packages/ui/vitest.config.ts` set its include to

    packages/scaffald-ui/src/**/*.{test,spec}.{ts,tsx}

The package has been at `packages/ui` since it was renamed. `root` is the
workspace root, so that glob resolved against a path that has not existed for
months: it matched zero files and vitest exited 0. Combined with
`passWithNoTests: true` in project.json, `nx run @scaffald/ui:test` reported
success while running nothing at all. 41 test files, 692 tests.

The config's TODO blamed "a double-path esbuild error in the NX executor" for
the wrong path. That no longer reproduces — with the include corrected,
`nx run @scaffald/ui:test --skip-nx-cache` passes.

Turning the tests on surfaced six failures. They are not new; they are what
had been hidden.

**useSidebarState: a crash, not a test problem.** `safeLocalStorage()` guarded
*reaching* `window.localStorage` but not reading or writing through it — and
those are the calls that actually throw. Safari in private mode, an iframe with
third-party cookies blocked, and an exhausted quota all return a real Storage
object whose getItem/setItem raise. The read runs inside a `useState`
initializer, so the throw propagated out of render and took down every page
that mounts a sidebar. Both accesses are now guarded.

**useResponsive: stale tests.** They were written against an older per-instance
implementation that read `window.innerWidth` each render, so they replaced
`global.window` with a plain object. The hook was since rewritten to a
module-level singleton store (one shared resize listener for the whole tree)
that reads `document.documentElement.clientWidth` and only re-reads on a
`resize` event. Against that, the mock could not work: the replacement window
had no `document`, and the mocked `addEventListener` never fired. Every
width-specific assertion was really asserting against jsdom's width at import
time, which is 0. Rewritten to move the real viewport and dispatch the real
event; several assertions that had been weakened to `expect(typeof value).toBe(
'number')` now check the value.

**Modal: a test that could only pass vacuously.** Modal ignores a backdrop
click within 200ms of opening. The test pinned `Date.now` to one fixed value to
clear that window, which guarantees the opposite — `openedAtRef` is stamped
from the same mocked clock at render, so the delta is always 0 and the handler
always returned early. Its sibling, asserting onClose is *not* called when
closeOnBackdropPress is false, passed for that reason rather than the intended
one. The clock now advances between opening and clicking.

692 passing, 0 failing. `passWithNoTests` is set to false so that a glob
matching nothing fails loudly instead of silently, which is the mechanism that
allowed this to persist.

Refs Scaffald/SaaS#469

Co-Authored-By: Claude Opus 5 <[email protected]>
@thinkclay
thinkclay merged commit e1be06d into main Sep 2, 2026
@thinkclay
thinkclay deleted the fix/469-vitest-include branch September 2, 2026 05:10
thinkclay added a commit to Scaffald/SaaS that referenced this pull request Sep 2, 2026
…ould not be committed (#702)

Two mechanisms that hid work rather than doing it.

**#469 — the tests.** `packages/ui/vitest.config.ts` set its include to
`packages/scaffald-ui/src/**`, a path that has not existed since the package
was renamed to `packages/ui`. `root` is the workspace root, so the glob matched
zero files and vitest exited 0; with `passWithNoTests: true`, nx reported
success while running nothing. 41 files, 692 tests. Fixed in Scaffald/ui#28,
along with the six failures that turning them on exposed — one of which was a
real crash: useSidebarState guarded reaching `window.localStorage` but not
reading through it, so Safari private mode or a blocked-cookie iframe threw out
of a `useState` initializer and took down every page with a sidebar.

`@scaffald/ui` is dropped from the `test:unit` and `affected:test` exclusions
and from prepush's TEST_EXCLUDES, so those 692 tests now gate merges. Verified:
`pnpm test:unit` passes across 8 projects with the package included.

**#470 — the hook.** A submodule pointer bump stages one path, `packages/ui`.
The pre-commit hook matches lint output against staged paths by substring, and
that path is a prefix of every file in the submodule — so a bump claimed 19 of
the submodule's 20 pre-existing violations as "errors in staged files" and
blocked the commit. The count is identical either side of the bump, which is
the proof it introduces none of them. Every pointer bump therefore had to use
--no-verify, which also skipped the checks that would have been useful.

Rather than exempt gitlinks outright, the hook now resolves a staged gitlink to
the files that actually changed inside the submodule between the old and new
pointer, so a bump still fails on violations it genuinely introduces. Measured
on a real bump: 19 claimed before, 0 after, while a bump touching Slider.tsx
still reports its 3. If the pointers cannot be diffed — submodule not fetched,
or newly added — the gitlink is dropped rather than guessed at; pre-push and CI
still lint it.

This commit is itself the test case: it carries a pointer bump and was
committed with the hook running, not with --no-verify.

Closes #469
Closes #470

Co-authored-by: Claude Opus 5 <[email protected]>
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