Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Register runtime-read files as watch dependencies in tests
When a test reads or renders files at runtime (templates, fixtures) instead of importing them, watch mode never reruns on their changes; register them as module dependencies (e.g. Vite's import.meta.glob with eager + ?url) and derive the test list from those keys.
Bad example
| 1 | test.for(globSync('views/**/index.njk'))('%s', async (template) => { |
| 2 | const html = await renderTemplate(template); |
| 3 | }); |
Explanation (EN)
The runner lists files via fs, so the module graph has no edge to them and watch mode never reruns when a template changes.
Objašnjenje (HR)
Runner lista fajlove kroz fs pa module graph nema vezu na njih i watch mode se nikad ne re-runa kad se template promijeni.
Good example
| 1 | const templates = import.meta.glob(['./**/{index,header}.njk', '!./base/**'], { query: '?url', import: 'default', eager: true }); |
| 2 |
|
| 3 | test.for(Object.keys(templates).filter((t) => t.endsWith('index.njk')))('%s', async (template) => { |
| 4 | const html = await renderTemplate(template); |
| 5 | }); |
Explanation (EN)
Eager glob imports create real module edges, so editing any matched file reruns the test in watch mode.
Objašnjenje (HR)
Eager glob importi stvaraju prave module veze pa uređivanje bilo kojeg fajla ponovno pokreće test u watch modu.