[MEDIUM] Add vitest suite for createCoreFetch + createI18n; wire into prepare #4
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
From audit #1.
Problem
No tests at all in
webapp-scaffold— the largest risk multiplier on every other audit finding.Remediation
Add vitest suite covering:
createCoreFetch: each hook, each response shape, 401/409/network paths.createI18n: resolver chain, miss cache, subscribe/notify.Wire
npm testinto thepreparescript so publish is gated on tests passing.Acceptance
npm testruns onprepare.createCoreFetchhook variants andcreateI18nhappy + miss paths.Effort: medium.
Agent Evaluation
Feasibility: Medium. webapp-scaffold currently has zero test infrastructure — no vitest, jsdom, or test setup. Bootstrapping it means adding
vitest,@vitest/ui(optional),jsdom, and possiblymswfor HTTP fixtures, plus a minimalvitest.config.ts. The library has three substantive units to cover:core-fetch.ts(~180 LOC) —createCoreFetchfactory, hook wiring (onUnauthorized,onConflict, response-shape branches, network-error path).i18n.ts(~80 LOC) — resolver chain, miss-cache, subscribe/notify.i18n-react.ts— small wrapper, can piggy-back oni18n.tstests.Surface area is small but the test count to be "useful" is meaningful — easily 25–35 cases.
Impact: Direct risk-reduction multiplier on every other audit finding. Once the harness exists, future fixes (#2, #3, #5) ship with regression guards instead of "manual smoke-test on the consumer".
Effort: Medium.
Recommendation: Accept.
Implementation plan
vitest,jsdom(fori18n-react.ts's React deps) to devDependencies. Minimalvitest.config.tssettingenvironment: 'jsdom'.src/core-fetch.test.ts— mockglobalThis.fetch(vitest'svi.fn); test:responseShape: 'body'and{response, body}for'full'.onUnauthorizedinvoked with the Response; promise rejects (per #1's documentation note).onConflictinvoked, error includes the parsed body.src/i18n.test.ts— synchronous resolver chain (lookup hits first dict), miss path returns key + caches, subscribe/notify fires once persetLocale.src/i18n-react.test.tsx—@testing-library/react(add to devDeps), one test that the hook re-renders on locale change.package.json— add"test": "vitest run","test:watch": "vitest". Wire intoprepare:"prepare": "tsc && vitest run"(drop the|| trueper audit-#1 LOW item).Decision needed
Check one (edit this comment):
core-fetch.tsonly — boot vitest, cover onlycreateCoreFetch(the highest-risk surface); leave i18n for a later issue. Smaller PR, addresses the audit's most concrete "untested code path" finding.Evaluated #4 — Medium, recommend accept; decision: full coverage vs core-fetch-only.
Implement Option A
Re-evaluation
Owner selected Option A — Full coverage as specced.
Acknowledged. Implementation will follow the original plan verbatim:
@testing-library/reactfori18n-react.test.tsx).src/core-fetch.test.ts— happy path (both response shapes), 401 →onUnauthorized, 409 →onConflict, network error, non-JSON 2xx pin.src/i18n.test.ts— resolver chain, miss-cache, subscribe/notify.src/i18n-react.test.tsx— re-render on locale change.package.json— addtest/test:watch; wireprepare = tsc && vitest run(drop|| true).Apply the
acceptedlabel to trigger implementation.Re-evaluated #4 — owner picked Option A (full coverage); awaiting accepted label.
Implemented #4 → commit
90c5ca2, version 0.3.7 (Option A: full coverage; 25 tests, vitest+jsdom+@testing-library/react, prepare gated on tests passing).