test(waas-engine): add vitest suite and node ssr container adapter setup
This commit is contained in:
53
tests/waasEngine.test.ts
Normal file
53
tests/waasEngine.test.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { loadWaasConfigs, FALLBACK_SITE_CONFIG, FALLBACK_THEME_CONFIG, FALLBACK_SMTP_CONFIG } from '../src/utils/configLoader';
|
||||
import { THEME_PRESETS } from '../src/utils/themePresets';
|
||||
|
||||
describe('WaaS Engine Core Unit Tests', () => {
|
||||
const testDataDir = path.join(process.cwd(), 'app', 'test_data');
|
||||
|
||||
beforeEach(() => {
|
||||
process.env.DATA_DIR = testDataDir;
|
||||
if (fs.existsSync(testDataDir)) {
|
||||
fs.rmSync(testDataDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (fs.existsSync(testDataDir)) {
|
||||
fs.rmSync(testDataDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('1. Should return fallbacks when JSON files do not exist (Zero-Crash Guarantee)', () => {
|
||||
const configs = loadWaasConfigs();
|
||||
expect(configs.siteConfig.siteName).toBe(FALLBACK_SITE_CONFIG.siteName);
|
||||
expect(configs.themeConfig.activePreset).toBe(FALLBACK_THEME_CONFIG.activePreset);
|
||||
expect(configs.smtpConfig.host).toBe(FALLBACK_SMTP_CONFIG.host);
|
||||
});
|
||||
|
||||
it('2. Should dynamically merge custom site.config.json', () => {
|
||||
fs.mkdirSync(testDataDir, { recursive: true });
|
||||
const customSite = { siteName: 'Custom Test Agency', hero: { title: 'Custom Title' } };
|
||||
fs.writeFileSync(path.join(testDataDir, 'site.config.json'), JSON.stringify(customSite), 'utf8');
|
||||
|
||||
const configs = loadWaasConfigs();
|
||||
expect(configs.siteConfig.siteName).toBe('Custom Test Agency');
|
||||
expect(configs.siteConfig.hero.title).toBe('Custom Title');
|
||||
expect(configs.siteConfig.hero.badge).toBe(FALLBACK_SITE_CONFIG.hero.badge);
|
||||
});
|
||||
|
||||
it('3. Should have 10 valid Theme Presets with root CSS color tokens', () => {
|
||||
const presetKeys = Object.keys(THEME_PRESETS);
|
||||
expect(presetKeys.length).toBe(10);
|
||||
expect(THEME_PRESETS.corporateDark.colors.bg).toBe('#0B0F19');
|
||||
expect(THEME_PRESETS.corporateDark.colors.accent).toBe('#38BDF8');
|
||||
});
|
||||
|
||||
it('4. Should support dynamic UIComponent elements in SectionConfig', () => {
|
||||
const heroElements = FALLBACK_SITE_CONFIG.hero.elements || [];
|
||||
expect(heroElements.length).toBeGreaterThan(0);
|
||||
expect(heroElements[0].type).toBe('badge');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user