5.9 KiB
5.9 KiB
Tasks: enterprise-browser-test-vite
Change ID: enterprise-browser-test-vite
Package: @suaveplan/test-vite
Target path: browser/dev/test-vite
Prerequisite packages on Verdaccio: none (no workspace runtime deps)
0. Pre-flight (non-negotiable)
- 0.1 Confirm clean working tree (
git statusreports nothing) and no in-flight worktrees with uncommitted work (git worktree listthengit statusin each) - 0.2 If any worktrees exist under
.claude/worktrees/, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (git worktree remove) before opening a new one — code that has been lost twice on main is the failure mode this guards against. - 0.3 Confirm the package set in
MANIFEST.mdmatchesfind packages -maxdepth 3 -name package.jsoncount. Drift here means a prior change archived without regenerating the manifest.
1. Scaffold
- Create directory tree per
proposal.md. package.jsonv0.0.0,"sideEffects": false.dependencies:@suaveplan/logger workspace:^,tslib catalog:buildpeerDependencies:vite,vitestdevDependencies:vitest catalog:testing,@vitest/coverage-istanbul catalog:testing,vite catalog:build,@suaveplan/testing workspace:^- Subpath exports:
".","./config/vite-library","./config/vite-app","./config/vitest","./config/vitest-browser","./setup/browser","./utils/tree-shake","./utils/bundle-size","./matchers","./ports"
tsconfig.json,vitest.config.ts(pool: forks).- Delete
export const test = "hi"placeholder fromsrc/index.ts.
2. Types (src/types/types.ts)
ViteLibraryOptions,ViteAppOptions,VitestOptions,VitestBrowserOptions,BrowserEnvOptions,SetupResult,TreeShakeResult,BundleSizeResult.- All option types validated by Zod with sensible defaults.
- Write
types.md.
3. Scope split documentation
- Document formal scope split in this change's OpenSpec entry:
test-vite= Vite/Vitest build config factories;@suaveplan/testing= polyfills + test utilities + fixtures. No overlap.
4. createViteLibraryConfig (src/config/vite-library/)
vite-library.ts—preserveModules: true,vite-plugin-dts, external@suaveplan/*peers, ESM-first output, configurableentry.- Options validated by Zod.
- Write
vite-library.test.ts(options validation, externals list, DTS flag). Writevite-library.md.
5. createViteAppConfig (src/config/vite-app/)
vite-app.ts— React/Vue plugin switch, env-var type declarations, hashing strategy.- Write
vite-app.test.ts. Writevite-app.md.
6. createVitestConfig (src/config/vitest/)
vitest.ts— defaults:pool: 'forks',setupFiles: ['@suaveplan/testing/polyfills'], Istanbul provider, reporters tuned for CI.- Accepts
environment,coverage,pooloverrides. - Write
vitest.test.ts(default pool is forks, Istanbul provider selected, polyfills in setupFiles). Writevitest.md.
7. createVitestBrowserConfig (src/config/vitest-browser/)
vitest-browser.ts— Playwright provider;fileParallelism: false; configurablebrowser(chromium/firefox/webkit);headlesstoggle.- Write
vitest-browser.test.ts. Writevitest-browser.md.
8. setupBrowserEnvironment (src/setup/browser/)
browser.ts— happy-dom / jsdom helper with switches:mockLocalStorage,mockServiceWorker,mockMatchMedia,mockResizeObserver.- Implementations use typed adapters — no
vi.stubGlobal. - Write
browser.test.ts(each mock flag). Writebrowser.md.
9. Tree-shake validator (src/utils/tree-shake/)
tree-shake.ts—verifyTreeShake(entry, expectedSymbols)builds with Rollup, asserts only listed symbols in output chunk.- Write
tree-shake.test.ts(synthetic package — verify dead code eliminated). Writetree-shake.md.
10. Bundle-size snapshot (src/utils/bundle-size/)
bundle-size.ts—snapshotBundleSize(entry, budgetBytes)writes.size.snap; fails when budget exceeded.- Write
bundle-size.test.ts. Writebundle-size.md.
11. Custom matchers (src/matchers/)
matchers.ts— typedexpect.extend:toBeAccessible(axe-core),toMatchDataURL,toHaveValidCSSVars.- Write
matchers.test.ts(each matcher pass + fail case). Writematchers.md.
12. Port helpers (src/ports/)
ports.ts—allocatePort(label)/releasePort(label)backed by a file lock; deterministic port assignment;getPortMap()for diagnostics.- Write
ports.test.ts(allocate, release, conflict avoidance). Writeports.md.
13. Proof-of-concept consumer migration
- Migrate one browser consumer (e.g.,
@suaveplan/react-tour) off its handwrittenvite.config.ts+vitest.config.tsonto the new factories. - Document the migration as an example in
README.md.
14. Integration test (tests/integration.test.ts)
- Build a synthetic library package end-to-end using
createViteLibraryConfig; assert ESM output, DTS files, externals. - Run
createVitestConfigin a child process; assertpool: forksand Istanbul provider. verifyTreeShakeon a test module; assert dead export eliminated.
15. Docs + verify
- Write
.mdper module (≥200 words, API reference, options table, example). - Write
README.mdwith scope-split table, subpath table, migration example. bunx turbo lint typecheck test --filter=@suaveplan/test-vite— green.bunx turbo test:coverage— 100% (currently near-zero).- No
@ts-expect-errorinsrc/or tests. No placeholder exports. - At least one consumer package migrated to new factories.
bun scripts/publish.ts --package @suaveplan/test-vite.- Archive to
openspec/archive/2026-04-24-enterprise-browser-test-vite/.