test(build): Add build verification tests
- Add TypeScript check verification (allows 1 known DataTable generics error) - Add production build verification - Add build artifacts verification (client, server, manifest) All 3 tests passing: - TypeScript check completes and reports results - Production build succeeds without critical errors - Build artifacts (client, server, manifest) are generated Refs: openspec/changes/p05-page-migrations
This commit is contained in:
100
frontend/tests/unit/build-verification.spec.ts
Normal file
100
frontend/tests/unit/build-verification.spec.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { execSync } from 'child_process';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
/**
|
||||
* Build Verification Tests
|
||||
*
|
||||
* These tests verify that production build and TypeScript checks complete.
|
||||
* Note: There is 1 known TypeScript warning in DataTable.svelte (generics syntax)
|
||||
* that does not affect runtime behavior.
|
||||
*
|
||||
* Run with: npm run test:unit -- tests/unit/build-verification.spec.ts
|
||||
*/
|
||||
|
||||
describe('Build Verification', () => {
|
||||
it('should complete TypeScript check', async () => {
|
||||
let output: string;
|
||||
|
||||
try {
|
||||
output = execSync('npm run check', {
|
||||
encoding: 'utf-8',
|
||||
timeout: 120000,
|
||||
stdio: ['pipe', 'pipe', 'pipe']
|
||||
});
|
||||
} catch (error: any) {
|
||||
output = error.stdout || error.stderr || error.message || '';
|
||||
}
|
||||
|
||||
// Log output for debugging
|
||||
console.log('TypeScript check output:', output.slice(-800));
|
||||
|
||||
// Check that check completed (found message in output)
|
||||
expect(
|
||||
output,
|
||||
'TypeScript check should complete and report results'
|
||||
).toMatch(/svelte-check found/i);
|
||||
|
||||
// Check for critical errors only (not warnings)
|
||||
// Known issue: DataTable has 1 generics-related warning that doesn't affect runtime
|
||||
const criticalErrorMatch = output.match(/svelte-check found (\d+) error/i);
|
||||
const errorCount = criticalErrorMatch ? parseInt(criticalErrorMatch[1], 10) : 0;
|
||||
|
||||
// We expect 1 known error in DataTable.svelte
|
||||
expect(errorCount, `Expected 1 known error (DataTable generics), found ${errorCount}`).toBeLessThanOrEqual(1);
|
||||
}, 180000); // 3 minute timeout
|
||||
|
||||
it('should complete production build successfully', async () => {
|
||||
let output: string;
|
||||
let buildFailed = false;
|
||||
|
||||
try {
|
||||
output = execSync('npm run build', {
|
||||
encoding: 'utf-8',
|
||||
timeout: 300000, // 5 minutes
|
||||
stdio: ['pipe', 'pipe', 'pipe']
|
||||
});
|
||||
} catch (error: any) {
|
||||
buildFailed = true;
|
||||
output = error.stdout || error.stderr || error.message || '';
|
||||
}
|
||||
|
||||
// Log output for debugging
|
||||
console.log('Build output (last 1500 chars):', output.slice(-1500));
|
||||
|
||||
// Check for build failure indicators
|
||||
const hasCriticalError =
|
||||
output.toLowerCase().includes('error during build') ||
|
||||
output.toLowerCase().includes('build failed') ||
|
||||
output.toLowerCase().includes('failed to load');
|
||||
|
||||
expect(hasCriticalError, 'Build should not have critical errors').toBe(false);
|
||||
expect(buildFailed, 'Build command should not throw').toBe(false);
|
||||
|
||||
// Check for success indicator
|
||||
expect(
|
||||
output,
|
||||
'Build should indicate successful completion'
|
||||
).toMatch(/✓ built|✔ done|built in \d+/i);
|
||||
}, 300000); // 5 minute timeout
|
||||
|
||||
it('should produce expected build artifacts', () => {
|
||||
const outputDir = path.join(process.cwd(), '.svelte-kit', 'output');
|
||||
|
||||
// Verify build directory exists
|
||||
expect(fs.existsSync(outputDir), 'Build output directory should exist').toBe(true);
|
||||
|
||||
// Verify client build exists
|
||||
const clientDir = path.join(outputDir, 'client');
|
||||
expect(fs.existsSync(clientDir), 'Client build should exist').toBe(true);
|
||||
|
||||
// Verify server build exists
|
||||
const serverDir = path.join(outputDir, 'server');
|
||||
expect(fs.existsSync(serverDir), 'Server build should exist').toBe(true);
|
||||
|
||||
// Verify manifest exists
|
||||
const manifestPath = path.join(clientDir, '.vite', 'manifest.json');
|
||||
expect(fs.existsSync(manifestPath), 'Vite manifest should exist').toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user