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

prerendering.spec.ts

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