Assessor_2.0/tests/config/vite-config-separation.test.ts

73 lines
3.8 KiB
TypeScript

import { existsSync, readFileSync } from 'node:fs';
import { describe, expect, it } from 'vitest';
const read = (path: string) => readFileSync(new URL(`../../${path}`, import.meta.url), 'utf8');
describe('Vite configuration boundaries', () => {
it('routes every npm workflow through its dedicated configuration', () => {
const scripts = JSON.parse(read('package.json')).scripts as Record<string, string>;
expect(scripts.dev).toBe('node scripts/dev-local.mjs');
expect(scripts['dev:client']).toContain('--config vite.client.config.ts');
expect(scripts['build:client']).toContain('--config vite.client.config.ts');
expect(scripts['build:server']).toContain('--config vite.server.config.ts');
expect(scripts.test).toContain('--config vitest.config.ts');
expect(scripts['test:watch']).toContain('--config vitest.config.ts');
expect(scripts['test:postgres']).toContain('--config vitest.config.ts');
});
it('starts the local client only after the backend health boundary is available', () => {
const launcher = read('scripts/dev-local.mjs');
expect(launcher).toContain("http://127.0.0.1:4173/api/v1/health");
expect(launcher).toContain("method: 'GET'");
expect(launcher).toContain("resolve(projectRoot, 'vite.client.config.ts')");
expect(launcher).toContain("resolve(projectRoot, 'vite.server.config.ts')");
expect(launcher).toContain("server: { host: '127.0.0.1', port: 5173, strictPort: true }");
expect(launcher.indexOf('await startServerBuildWatcher()')).toBeLessThan(launcher.indexOf('clientServer = await createServer'));
});
it('owns, versions, rebuilds, and safely restarts the local development backend', () => {
const launcher = read('scripts/dev-local.mjs');
expect(launcher).toContain("build: { watch: {} }");
expect(launcher).toContain("event.code !== 'END'");
expect(launcher).toContain('restartChain = restartChain.then(activateBuiltBackend)');
expect(launcher).toContain('ASSESSOR_RELEASE_ID: releaseId');
expect(launcher).toContain('ASSESSOR_DEVELOPMENT_INSTANCE_ID: developmentInstanceId');
expect(launcher).toContain("health?.releaseId === releaseId && health?.developmentInstanceId === developmentInstanceId");
expect(launcher).toContain('Reclaiming the previously managed development backend');
expect(launcher).toContain('Port 4173 is occupied by an unmanaged or incompatible backend');
expect(launcher).toContain('Backend rebuild failed; the last healthy backend remains active.');
expect(launcher).not.toContain('Backend connected:');
});
it('keeps client, server, and test concerns isolated', () => {
const client = read('vite.client.config.ts');
const server = read('vite.server.config.ts');
const tests = read('vitest.config.ts');
const compatibility = read('vite.config.ts');
const nodeConfig = read('tsconfig.node.json');
expect(client).toContain("cacheDir: 'node_modules/.vite-client'");
expect(client).toContain("outDir: 'dist'");
expect(client).toContain("from '@vitejs/plugin-react'");
expect(client).not.toContain('test: {');
expect(server).toContain("cacheDir: 'node_modules/.vite-server'");
expect(server).toContain("outDir: 'dist-server'");
expect(server).toContain('ssr: true');
expect(server).not.toContain('@vitejs/plugin-react');
expect(tests).toContain("cacheDir: 'node_modules/.vite-tests'");
expect(tests).toContain("from 'vitest/config'");
expect(tests).toContain('tests/**/*.test.tsx');
expect(tests).not.toContain('build: {');
expect(compatibility).toContain("from './vite.client.config'");
expect(compatibility).not.toContain('defineConfig');
expect(nodeConfig).toContain('"noEmit": true');
expect(existsSync(new URL('../../vite.config.js', import.meta.url))).toBe(false);
expect(existsSync(new URL('../../vite.config.d.ts', import.meta.url))).toBe(false);
});
});