Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

prerendering.spec.ts

48 lines1.9 KB

1import { existsSync, readFileSync } from 'node:fs'
2import { join } from 'node:path'
3import { expect } from '@playwright/test'
4import { test } from '@tanstack/router-e2e-utils'
5import { isPrerender } from './utils/isPrerender'
6​
7const distDir = join(
8 process.cwd(),
9 process.env.E2E_DIST_DIR ?? 'dist',
10 'client',
12​
13test.describe('Prerender Static Path Discovery', () => {
14 test.skip(!isPrerender, 'Skipping since not in prerender mode')
15 test.describe('Build Output Verification', () => {
16 test('should automatically discover and prerender static routes', () => {
17 // Check that static routes were automatically discovered and prerendered
18 // These static routes should be automatically discovered and prerendered
19 expect(existsSync(join(distDir, 'index.html'))).toBe(true)
20 expect(existsSync(join(distDir, 'posts/index.html'))).toBe(true)
21 expect(existsSync(join(distDir, 'deferred/index.html'))).toBe(true)
22 expect(existsSync(join(distDir, 'scripts/index.html'))).toBe(true)
23 expect(existsSync(join(distDir, 'inline-scripts/index.html'))).toBe(true)
24 expect(
25 existsSync(join(distDir, 'specialChars/λŒ€ν•œλ―Όκ΅­/index.html')),
26 ).toBe(true)
27​
28 // Pathless layouts should NOT be prerendered (they start with _)
29 expect(existsSync(join(distDir, '_layout', 'index.html'))).toBe(false) // /_layout
30​
31 // API routes should NOT be prerendered
32​
33 expect(existsSync(join(distDir, 'api', 'users', 'index.html'))).toBe(
34 false,
35 ) // /api/users
36 })
37 })
38​
39 test.describe('Static Files Verification', () => {
40 test('should contain prerendered content in posts.html', () => {
41 expect(existsSync(join(distDir, 'posts/index.html'))).toBe(true)
42​
43 // "Select a post." should be in the prerendered HTML
44 const html = readFileSync(join(distDir, 'posts/index.html'), 'utf-8')
45 expect(html).toContain('Select a post.')
46 })
47 })
48})