source: Klonkt/test/routes-load.test.js@ 4fbe2c1

main
Last change on this file since 4fbe2c1 was 329873e, checked in by Robin Genis <roboburr@…>, 6 weeks ago

Herstel: een losse ) sloopte guardian.js, en dus sound-fabrics

Bij het feature-bewust maken van de voorstel-route heb ik de arrow-functie
omgezet naar een gewone functie en de afsluiter laten staan: het lichaam eindigt
op }); in plaats van }. Dat is een syntaxfout, guardian.js laadde niet meer, en
de server startte niet meer op. sound-fabrics gaf 502.

Erger dan de fout is dat 280 tests groen stonden. Geen enkele test importeert
een route-bestand: de suite dekte de logica en miste de bedrading. Een
syntaxfout in een route was daarmee onzichtbaar tot een server niet meer
opstartte.

Daarom test/routes-load.test.js: importeer elk bestand in src/routes en laat
het vallen als het niet laadt. Geverifieerd tegen de kapotte versie, die faalt
er wel degelijk op.

Changed files:
src/routes/guardian.js

  • de losse ); aan het eind van proposeGated

New file:
test/routes-load.test.js

  • elk route-bestand moet laden; dekt parse-fouten, kapotte imports en namen die verhuisd zijn

remarks: 322 tests groen (42 nieuw, een per route-bestand).

-robo
Co-Authored-By: Claude Opus 5 <noreply@…>

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[329873e]1// Every route file must at least PARSE and load.
2//
3// This exists because a stray `);` in routes/guardian.js took sound-fabrics.com
4// down while 280 tests were green: not one of them imports a route file, so a
5// syntax error there is invisible to the suite and only shows up as a server
6// that will not boot. The tests covered the logic and missed the wiring.
7//
8// Cheap to run, and it fails on exactly the class of mistake that a hand-edited
9// route is prone to: an unbalanced brace, a bad import, a name that moved.
10import { test } from 'node:test';
11import assert from 'node:assert/strict';
12import fs from 'fs';
13import path from 'path';
14
15process.env.DATABASE_PATH = ':memory:';
16process.env.PUBLIC_BASE_URL = 'https://test.example';
17
18const dbMod = await import('../src/config/database.js');
19dbMod.initializeDatabase();
20
21const dir = new URL('../src/routes/', import.meta.url);
22const files = fs.readdirSync(dir).filter((f) => f.endsWith('.js')).sort();
23
24test('there are route files to check', () => {
25 assert.ok(files.length > 10, `expected the routes directory, found ${files.length} files`);
26});
27
28for (const f of files) {
29 test(`routes/${f} loads`, async () => {
30 // A throwing import is the failure we are after: a parse error, a missing
31 // export, a bad path. Anything the module does at load time counts too,
32 // because the server does exactly this on boot.
33 await import(new URL(f, dir).href);
34 });
35}
36
37test('the server module itself loads', async () => {
38 // The whole wiring in one go: every router, every service it pulls in.
39 const src = fs.readFileSync(path.join(process.cwd(), 'src', 'server.js'), 'utf8');
40 assert.match(src, /routes/, 'server.js is the file that mounts the routers');
41});
Note: See TracBrowser for help on using the repository browser.