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

prerendering.spec.ts

43 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​
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, 'deferred/index.html'))).toBe(true)
18 expect(existsSync(join(distDir, 'scripts/index.html'))).toBe(true)
19 expect(existsSync(join(distDir, 'inline-scripts/index.html'))).toBe(true)
20 expect(existsSync(join(distDir, 'λŒ€ν•œλ―Όκ΅­/index.html'))).toBe(true)
21​
22 // Pathless layouts should NOT be prerendered (they start with _)
23 expect(existsSync(join(distDir, '_layout', 'index.html'))).toBe(false) // /_layout
24​
25 // API routes should NOT be prerendered
26​
27 expect(existsSync(join(distDir, 'api', 'users', 'index.html'))).toBe(
28 false,
29 ) // /api/users
30 })
31 })
32​
33 test.describe('Static Files Verification', () => {
34 test('should contain prerendered content in posts.html', () => {
35 const distDir = join(process.cwd(), 'dist', 'client')
36 expect(existsSync(join(distDir, 'posts/index.html'))).toBe(true)
37​
38 // "Select a post." should be in the prerendered HTML
39 const html = readFileSync(join(distDir, 'posts/index.html'), 'utf-8')
40 expect(html).toContain('Select a post.')
41 })
42 })
43})