Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
fullstack ruleP1universalStack: Vitest / build tooling
testingintegrationmockingtest-design
Test units through their real integration point, not their internals
Don't write tests that hard-code a unit's internal structure or hand-mock data the framework should provide; drive the unit through its actual host (e.g. run a real build for a build plugin) so the test catches what the real graph would.
PR: hegnar-zephr-components · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | // hand-built fake module graph + asserting on plugin hook shape |
| 2 | const plugin = ancestorTrace() as unknown as { generateBundle: () => Promise<void> }; |
| 3 | await plugin.generateBundle.call({ getModuleInfo: mockGraph(fakeDeps) }); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | // run the plugin through Vite itself with the real config, stub env, let Vite build the graph |
| 2 | vi.stubEnv('DIFF', 'true'); |
| 3 | await build(viteConfigWith(ancestorTrace())); |
| 4 | expect(logger.info).toHaveBeenCalledWith(expect.stringContaining('index.html')); |
Explanation (EN)
Objašnjenje (HR)