// Load the JIT compiler BEFORE any Angular router/common imports import '@angular/compiler'; import { describe, it, expect, vi, beforeEach } from 'vitest'; // Mock the @angular/ssr/node imports that pull in Node.js http server code // — we only want to test PRERENDERED_ROUTES and isPrerenderedRoute here. vi.mock('@angular/ssr/node', () => ({ AngularNodeAppEngine: class {}, createNodeRequestHandler: (fn: Function) => fn, isMainModule: () => false, writeResponseToNodeResponse: vi.fn(), })); vi.mock('node:http', () => ({ default: { createServer: vi.fn() }, })); import { PRERENDERED_ROUTES, isPrerenderedRoute } from './server'; describe('SSR server — server.ts', () => { describe('PRERENDERED_ROUTES', () => { it('should contain exactly 5 routes', () => { expect(PRERENDERED_ROUTES).toHaveLength(5); }); it('should include the home route', () => { expect(PRERENDERED_ROUTES).toContain('/'); }); it('should include /about', () => { expect(PRERENDERED_ROUTES).toContain('/about'); }); it('should include /schedule', () => { expect(PRERENDERED_ROUTES).toContain('/schedule'); }); it('should include /events', () => { expect(PRERENDERED_ROUTES).toContain('/events'); }); it('should include /contact', () => { expect(PRERENDERED_ROUTES).toContain('/contact'); }); }); describe('isPrerenderedRoute()', () => { it('should match exact prerendered paths', () => { expect(isPrerenderedRoute('/')).toBe(true); expect(isPrerenderedRoute('/about')).toBe(true); expect(isPrerenderedRoute('/schedule')).toBe(true); expect(isPrerenderedRoute('/events')).toBe(true); expect(isPrerenderedRoute('/contact')).toBe(true); }); it('should match paths with trailing slashes', () => { expect(isPrerenderedRoute('/about/')).toBe(true); expect(isPrerenderedRoute('/schedule/')).toBe(true); expect(isPrerenderedRoute('/events/')).toBe(true); expect(isPrerenderedRoute('/contact/')).toBe(true); }); it('should match paths with query strings', () => { expect(isPrerenderedRoute('/about?foo=bar')).toBe(true); expect(isPrerenderedRoute('/schedule?day=monday')).toBe(true); }); it('should match paths with fragments', () => { expect(isPrerenderedRoute('/events#upcoming')).toBe(true); }); it('should reject non-prerendered routes', () => { expect(isPrerenderedRoute('/login')).toBe(false); expect(isPrerenderedRoute('/admin')).toBe(false); expect(isPrerenderedRoute('/nonexistent')).toBe(false); expect(isPrerenderedRoute('/admin/dashboard')).toBe(false); }); it('should handle full URLs', () => { expect(isPrerenderedRoute('https://kmtnflower.org/about')).toBe(true); expect(isPrerenderedRoute('http://localhost:4200/events')).toBe(true); expect(isPrerenderedRoute('https://kmtnflower.org/login')).toBe(false); }); it('should normalise root path — "/" stays "/"', () => { expect(isPrerenderedRoute('/')).toBe(true); }); }); });