1- import { existsSync } from 'node:fs'
1+ import { existsSync , readFileSync } from 'node:fs'
22import { join } from 'node:path'
33import { expect } from '@playwright/test'
44import { test } from '@tanstack/router-e2e-utils'
@@ -8,10 +8,10 @@ test.describe('Prerender Static Path Discovery', () => {
88 test ( 'should automatically discover and prerender static routes' , ( ) => {
99 // Check that static routes were automatically discovered and prerendered
1010 const distDir = join ( process . cwd ( ) , 'dist' , 'client' )
11-
11+
1212 // These static routes should be automatically discovered and prerendered
1313 expect ( existsSync ( join ( distDir , 'index.html' ) ) ) . toBe ( true ) // / (index)
14- expect ( existsSync ( join ( distDir , 'posts.html' , ) ) ) . toBe ( true ) // /posts
14+ expect ( existsSync ( join ( distDir , 'posts.html' ) ) ) . toBe ( true ) // /posts
1515 expect ( existsSync ( join ( distDir , 'users.html' ) ) ) . toBe ( true ) // /users
1616 expect ( existsSync ( join ( distDir , 'deferred.html' ) ) ) . toBe ( true ) // /deferred
1717 expect ( existsSync ( join ( distDir , 'scripts.html' ) ) ) . toBe ( true ) // /scripts
@@ -20,42 +20,32 @@ test.describe('Prerender Static Path Discovery', () => {
2020
2121 // Pathless layouts should NOT be prerendered (they start with _)
2222 expect ( existsSync ( join ( distDir , '_layout' , 'index.html' ) ) ) . toBe ( false ) // /_layout
23-
23+
2424 // API routes should NOT be prerendered
25- expect ( existsSync ( join ( distDir , 'api' , 'users' , 'index.html' ) ) ) . toBe ( false ) // /api/users
25+
26+ expect ( existsSync ( join ( distDir , 'api' , 'users' , 'index.html' ) ) ) . toBe (
27+ false ,
28+ ) // /api/users
2629 } )
2730 } )
2831
29- test . describe ( 'Static Route Prerendering Verification' , ( ) => {
30- test ( 'should serve prerendered home page with server-side content' , async ( { page } ) => {
31- await page . goto ( '/' )
32-
33- // Verify the page loads and contains expected content
34- await expect ( page . locator ( 'h3' ) ) . toContainText ( 'Welcome Home!!!' )
35-
36- // Check that it was server-side rendered (no hydration flicker)
37- const html = await page . content ( )
38- expect ( html ) . toContain ( 'Welcome Home!!!' ) // Content should be in initial HTML
39- expect ( html ) . toContain ( 'Hello from a custom component!' ) // Component content should be in initial HTML
40- } )
32+ test . describe ( 'Static Files Verification' , ( ) => {
33+ test ( 'should contain prerendered content in posts.html' , async ( ) => {
34+ const distDir = join ( process . cwd ( ) , 'dist' , 'client' )
35+ expect ( existsSync ( join ( distDir , 'posts.html' ) ) ) . toBe ( true ) // /posts
4136
42- test ( 'should serve prerendered posts index page' , async ( { page } ) => {
43- await page . goto ( '/posts' )
44- // domContentLoaded event
45- await page . waitForLoadState ( 'domcontentloaded' )
46- // Check for server-side rendered content
47- const html = await page . content ( )
48- await page . pause ( ) ;
37+ // "Select a post." should be in the prerendered HTML
38+ const html = readFileSync ( join ( distDir , 'posts.html' ) , 'utf-8' )
4939 expect ( html ) . toContain ( 'Select a post.' ) // Content should be in initial HTML
5040 } )
5141
52- test ( 'should serve prerendered users index page ' , async ( { page } ) => {
53- await page . goto ( '/users ')
54-
55- // Check for server-side rendered content
56- const html = await page . content ( )
57- await page . pause ( ) ;
42+ test ( 'should contain prerendered content in users.html ' , async ( ) => {
43+ const distDir = join ( process . cwd ( ) , 'dist' , 'client ')
44+ expect ( existsSync ( join ( distDir , 'users.html' ) ) ) . toBe ( true ) // /users
45+
46+ // "Select a user." should be in the prerendered HTML
47+ const html = readFileSync ( join ( distDir , 'users.html' ) , 'utf-8' )
5848 expect ( html ) . toContain ( 'Select a user.' ) // Content should be in initial HTML
5949 } )
6050 } )
61- } )
51+ } )
0 commit comments