Commit Graph
4 Commits
Author SHA1 Message Date
GandMao Nakamoto 9c4db60947 chore: migrate from jest to vitest (#429)
* chore: migrate from jest to vitest

Retires jest in favor of vitest across the whole test suite (541 files,
7780 tests, 100% passing both before and after -- same counts as the
jest baseline, nothing lost or skipped). Same fleet-wide migration
pattern already shipped in botsmann and aoz-housing.

What changed:
- vitest.config.ts / vitest.setup.ts replace jest.config.js /
  jest.setup.js. Single jsdom environment (matching this repo's
  next/jest config) with per-file `@vitest-environment node` overrides
  where jest used `@jest-environment node` (241 files -- vitest supports
  the same docblock convention under a different tag name).
- next-intl's moduleNameMapper aliased both the bare specifier and every
  subpath (next-intl/routing, next-intl/navigation) to __mocks__/next-intl.js;
  vitest's resolve.alias needs the same regex-based subpath match, and the
  mock file itself needed converting off jest.fn()/CJS require to
  vi.fn()/ESM import (nothing else used it, so it never surfaced under jest).
- jest.* -> vi.* across the board: fn/mock/spyOn/clearAllMocks/etc.,
  jest.requireActual -> await vi.importActual (vitest has no sync
  variant), jest.requireMock -> await import() (a dynamic import of an
  already-vi.mock()'d specifier resolves to the mock), jest.setTimeout ->
  vi.setConfig({ testTimeout }), jest.isolateModules -> vi.resetModules()
  + await import() (vitest has no direct equivalent), bare require()
  calls inside test bodies -> await import() (vitest's ESM runtime has no
  require() that understands the `@/` Vite alias).
- Two genuine jest/vitest behavioral differences, not just API renames:
  vitest's vi.fn() invokes `new Foo()` on the mockImplementation itself
  (jest.fn() does not), so any mock standing in for a constructor
  (Audio, pg's Pool, @aws-sdk/client-s3's S3Client/PutObjectCommand/
  DeleteObjectCommand) needed its arrow-function implementation changed
  to a real function. And @testing-library's waitFor polls with real
  timers, which hangs once vi.useFakeTimers() is active in the same
  test -- the two debounce-search tests in useMarketplaceListings that
  combined both now assert directly after an explicit
  vi.advanceTimersByTimeAsync() + microtask flush instead of polling.
- Partial mocks (fs, sharp, and several @/db/schema* mocks) needed the
  same treatment already documented from the aoz-housing migration:
  vitest validates a mocked module's exports strictly, so a default
  import needs a `default` key in the mock factory's return value (jest
  didn't check this), and every export the mocked module's *transitive*
  importers reach for has to actually be present.
- vitest's own Mock/MockedFunction/MockedClass/MockInstance/Mocked types
  replace the jest.Mock family (SpyInstance is renamed MockInstance).
- One real source fix, not a test-only shim: blog-translate.ts zeroed
  its retry backoff under test by checking `process.env.JEST_WORKER_ID`;
  vitest sets `VITEST` instead, so two of its tests were hitting the
  real 2s/4s production backoff and timing out. Now checks both.
- package.json: test/test:watch/test:coverage/test:i18n scripts point
  at vitest; jest, @types/jest, jest-environment-jsdom dropped from
  devDependencies (@testing-library/jest-dom stays -- it's a matcher
  library, not jest-specific, and vitest uses it too).
- vitest-globals.d.ts (`/// <reference types="vitest/globals" />`)
  replaces the ambient describe/it/expect types @types/jest used to
  provide, without touching tsconfig's `types` array (which has no
  explicit list today, so every other @types/* package stays
  auto-included exactly as before).
- A related, pre-existing typecheck gap this migration exposed rather
  than introduced: `require('@/lib/schemas')` returned an untyped `any`
  under jest/CJS, so a cast like `as { validateBody: Mock }` type-checked
  even though the shapes don't really overlap. `await import(...)` is
  properly typed against the real module, so those same casts now need
  `as unknown as {...}` (or `as any` for the common case of a plain
  destructured mock-only import) -- a standard TS idiom, not a behavior
  change, verified by a full green `npm run typecheck` and `npm run lint`
  alongside the test run.

No source-level logic changes outside the one RETRY_BASE_MS env-var
guard above. `npm run typecheck`, `npm run lint`, and `npm run test`
(vitest) all pass clean.

* fix(deps): regenerate lockfile without --legacy-peer-deps

The previous commit's package-lock.json was produced with
--legacy-peer-deps (needed at the time to work around an
@vitejs/plugin-react / @rolldown/plugin-babel optional-peer conflict).
That flag changes npm's resolution algorithm significantly and produced
a lockfile missing large dependency subtrees entirely -- webpack and
everything under it -- causing real CI's `npm ci` (a strict,
lockfile-must-match-package.json install) to fail with EUSAGE before a
single test could run.

A plain `npm install` (no flag) resolves the same peer conflict fine
with warnings only, and `npm ci` against the regenerated lockfile now
succeeds cleanly. Verified: npm ci, npm run typecheck, npm run lint,
and the full vitest suite (541/541 files, 7780/7780 tests) all pass
against this lockfile.

* style: run prettier over the vitest migration

The scripted jest->vitest rewrites in the previous two commits weren't
run through prettier, and CI's Code Quality Checks job caught it:
"Code style issues found in 152 files." Converged in a single
`npm run format` pass; verified no eslint-disable-next-line or
@ts-expect-error directive detached from its target line, and
typecheck/lint/test all still pass clean.

* fix(test): drop a hoisted vi.mock that raced its own per-test override

audit.test.ts had both a hoisted, file-level `vi.mock('@/db', ...)` and
a per-test `vi.doMock('@/db', ...)` inside beforeEach that reassigns
valuesSpy fresh after vi.resetModules(). This is a documented vitest
anti-pattern: after resetModules(), which of the two mock
registrations actually backs the next import of '@/db' depends on
internal cache-invalidation timing, not test source order. It surfaced
as an intermittent "undefined is not a spy" on CI (real, dedicated
runner -- not local machine contention) roughly 1 run in 4: the
hoisted mock's plain `insert: vi.fn()` (no values() return) occasionally
won the race, so valuesSpy was never assigned by the doMock factory
that test iteration.

beforeEach runs before every test including the first, so the per-test
doMock alone is sufficient -- no top-level fallback needed. Verified
5 consecutive clean runs of this file after the fix.

---------

Co-authored-by: Mao Nakamoto <41178744+maonakamoto@users.noreply.github.com>
2026-09-02 10:43:17 +02:00
GandClaude Opus 5 a21d8906af chore: add a formatter, and close a CSS comment that was never closed (#419)
* chore: add a formatter, matching the style this repo already writes

singleQuote=true was chosen by counting this repo's own
imports, not by fleet decree. The fleet is genuinely split and the two repos
that already had a .prettierrc disagreed with each other, so there was no
standard to restore. Quote style does not cross repo boundaries; having a
gate does.

Markdown is ignored for now — prettier rewraps prose, which would bury the
real diff.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* style: format with prettier, and close a comment that was never closed

The formatter refused this repo outright, which turned out to be a real defect
rather than a tooling complaint. kivitendo-intake.css opens a header comment,
and line 17 contains an inner /* ⚠ PRÜFEN */ — CSS comments do not nest, so
that inner terminator CLOSES the header. Everything after it is parsed as CSS
until the stray */ on line 20. A browser mis-parses it the same way.

The file exists in two places (public/presentations/ and deliverables/), both
carrying the same defect; fixing one still failed the gate, which is how the
duplicate surfaced at all.

Mechanical otherwise. This SHA is listed in .git-blame-ignore-revs.

* chore: teach git blame to skip the reformat

* fix: undo a 3-way merge duplication in AdminSidebar.tsx

Merging main with -X theirs duplicated a 30-line block: main's currency-sweep
commit and this branch's prettier reformat both touched overlapping lines in
the single-destination-group render path, and the -X theirs strategy inserted
rather than replaced, leaving two near-identical copies and a dangling closing
brace — SyntaxError: ',' expected at line 298.

The branch has no legitimate change to this file's logic, only formatting, so
main's content is correct outright. Took it wholesale rather than hand-editing
the merge result.

* fix(lint): reattach 5 directives the reformat detached

Four eslint-disable-next-line sites for react-hooks/set-state-in-effect and one
@ts-expect-error, all the same defect: the directive sat above useEffect( (or
above a JSX element), while the statement that actually errors is 1-2 lines
further down inside the block. eslint/tsc report at the real statement; the
directive, still bound to its original line number, protects nothing there.

TimecardReviewDrawer.tsx (x2), DataEntryTabs.tsx, AppointmentBookingForm.tsx,
CreatePoolModal.tsx. Same root cause documented for hirnli, fleetcrown and
ivy-portal earlier today — a positional directive is a hidden dependency on
formatting, and this is the fourth distinct shape it's taken.

* fix(i18n): restore a same-line audit-exemption marker

Fifth shape of today's positional-directive defect, this time the repo's own
i18n-hardcoded-audit convention rather than eslint or tsc: a // i18n-ok comment
exempts a hardcoded string only when it trails the SAME line. prettier wrapped
this one if-statement's long condition onto its own line, leaving the marker
on the return statement below — the exact sibling one line down
('fortgeschrittene bis experten') stayed on one line because it was short
enough not to wrap, and it alone kept passing.

Restored the one-line form and added // prettier-ignore so a future reformat
cannot re-split it. Verified against the real audit script locally: 0 new
violations.

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-31 13:35:50 +00:00
g-butandClaude Sonnet 4.6 81c9cc61f6 test(mocks): add defineRouting + createNavigation to next-intl mock
Batch-replacing next/link with @/i18n/navigation caused 2 test suites
to fail: the i18n navigation module calls defineRouting and
createNavigation from next-intl sub-paths, which were not stubbed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-27 12:03:09 +02:00
g-butandClaude Sonnet 4.6 e72c864f4c fix(tests): unblock next-intl ESM in Jest — mock + transform config
Two test suites were crashing with "Unexpected token 'export'" because
ConfirmDialog now imports useTranslations (next-intl uses ESM-only builds).

Fix:
- Add next-intl and use-intl to transformIgnorePatterns exception list
- Add __mocks__/next-intl.js returning key-passthrough stubs, mapped via
  moduleNameMapper so components render without NextIntlClientProvider

Result: 27 suites / 354 tests all green (was 2 failing suites).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 22:19:22 +02:00