Repository navigation
fix(test): the vitest include pointed at a directory that does not exist, so 692 tests never ran - #28
Merged
Merged
Conversation
…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
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The mechanism
vitest.config.tsset its include to:The package has been at
packages/uisince it was renamed.rootis the workspace root, so that glob resolved against a path that has not existed for months — it matched zero files and vitest exited 0. WithpassWithNoTests: trueinproject.json,nx run @scaffald/ui:testreported 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-cachepasses.What turning them on surfaced
Six failures, none of them new.
useSidebarState— a real crashsafeLocalStorage()guarded reachingwindow.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 realStorageobject whosegetItem/setItemraiseSecurityError/QuotaExceededError.The read sits inside a
useStateinitializer, so the throw propagated out of render and took down every page that mounts a sidebar. Both accesses are now guarded.useResponsive— stale testsWritten against an older per-instance implementation that read
window.innerWidthon every render, so they replacedglobal.windowwith 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 aresizeevent.Against that implementation the mock could never work: the replacement window had no
document, and the mockedaddEventListenernever 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 vacuouslyModal 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.nowto a single fixed value to clear that window — which guarantees the opposite.openedAtRefis stamped from the same mocked clock at render, soDate.now() - openedAtRef.currentis always 0 and the handler always returned early.Its sibling — asserting
onCloseis not called whencloseOnBackdropPressis false — was passing for that reason rather than the intended one. The clock now advances between opening and clicking.Result
692 passing, 0 failing.
passWithNoTestsis nowfalse, 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