|
1 | 1 | import { describe, expect, it } from 'vitest'; |
2 | | -import { buildRouteTable, normalizeRoute } from './httpMetrics'; |
| 2 | +import { buildRouteTable, initRouteTable, normalizeRoute } from './httpMetrics'; |
3 | 3 |
|
4 | 4 | // Mirrors the shape and ordering of the real .next/routes-manifest.json: |
5 | 5 | // dynamic routes are listed in Next's resolution priority, with catch-alls |
@@ -40,6 +40,20 @@ const maxLabels = table.staticPages.size |
40 | 40 | + 2; // + '/_next', 'other' |
41 | 41 |
|
42 | 42 | describe('normalizeRoute', () => { |
| 43 | + it('discards a previously loaded table when initialization fails', () => { |
| 44 | + expect(initRouteTable({ |
| 45 | + staticRoutes: [{ page: '/api/health' }], |
| 46 | + dynamicRoutes: [], |
| 47 | + })).toBe(true); |
| 48 | + expect(normalizeRoute('/api/health')).toBe('/api/health'); |
| 49 | + |
| 50 | + expect(initRouteTable({ |
| 51 | + staticRoutes: [], |
| 52 | + dynamicRoutes: [{ page: '/broken', regex: '[' }], |
| 53 | + })).toBe(false); |
| 54 | + expect(normalizeRoute('/api/health')).toBe('other'); |
| 55 | + }); |
| 56 | + |
43 | 57 | it('maps the root path', () => { |
44 | 58 | expect(normalizeRoute('/', table)).toBe('/'); |
45 | 59 | expect(normalizeRoute('', table)).toBe('/'); |
|
0 commit comments