// Server F as the image runs it: built by the package's own build script // and started with node. Without its environment it stops at once and says // what is missing — which it can only say when the bundle loads at all (a // bundled library that declared createRequire again kept it from loading). import { spawnSync } from 'node:child_process'; import { fileURLToPath } from 'node:url'; import { describe, expect, it } from 'vitest'; const server = fileURLToPath(new URL('..', import.meta.url)); describe('the built server', () => { it('loads, and stops for want of its environment', () => { const built = spawnSync('npm', ['run', 'build'], { cwd: server, encoding: 'utf8' }); expect(built.status, built.stderr).toBe(0); const started = spawnSync(process.execPath, ['dist/main.mjs'], { cwd: server, encoding: 'utf8', env: { PATH: process.env.PATH }, timeout: 20_000 }); expect(started.status, started.stderr).toBe(1); expect(JSON.parse(started.stdout.trim().split('\n').at(-1)!)).toMatchObject({ event: 'config.missing', variables: ['DATABASE_URL', 'FILIUS_TICKET_SECRET', 'FILIUS_SERVICE_KEY', 'FILIUS_ORIGINS'], }); }, 60_000); });