| [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.
|
|---|
| 10 | import { test } from 'node:test';
|
|---|
| 11 | import assert from 'node:assert/strict';
|
|---|
| 12 | import fs from 'fs';
|
|---|
| 13 | import path from 'path';
|
|---|
| 14 |
|
|---|
| 15 | process.env.DATABASE_PATH = ':memory:';
|
|---|
| 16 | process.env.PUBLIC_BASE_URL = 'https://test.example';
|
|---|
| 17 |
|
|---|
| 18 | const dbMod = await import('../src/config/database.js');
|
|---|
| 19 | dbMod.initializeDatabase();
|
|---|
| 20 |
|
|---|
| 21 | const dir = new URL('../src/routes/', import.meta.url);
|
|---|
| 22 | const files = fs.readdirSync(dir).filter((f) => f.endsWith('.js')).sort();
|
|---|
| 23 |
|
|---|
| 24 | test('there are route files to check', () => {
|
|---|
| 25 | assert.ok(files.length > 10, `expected the routes directory, found ${files.length} files`);
|
|---|
| 26 | });
|
|---|
| 27 |
|
|---|
| 28 | for (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 |
|
|---|
| 37 | test('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 | });
|
|---|