11import { expect , test } from '@playwright/test'
2- import { type Fixture , useFixture } from './fixture'
2+ import { setupInlineFixture , type Fixture , useFixture } from './fixture'
33import {
44 expectNoReload ,
55 testNoJs ,
@@ -42,6 +42,107 @@ test.describe('build-no-ssr', () => {
4242 } )
4343} )
4444
45+ test . describe ( ( ) => {
46+ const root = 'examples/e2e/temp/react-compiler'
47+
48+ test . beforeAll ( async ( ) => {
49+ await setupInlineFixture ( {
50+ src : 'examples/starter' ,
51+ dest : root ,
52+ files : {
53+ 'vite.config.ts' : /* js */ `
54+ import rsc from '@vitejs/plugin-rsc'
55+ import react from '@vitejs/plugin-react'
56+ import { defineConfig } from 'vite'
57+
58+ export default defineConfig({
59+ plugins: [
60+ react({
61+ babel: { plugins: ['babel-plugin-react-compiler'] },
62+ }).map((p) => ({
63+ ...p,
64+ applyToEnvironment: (e) => e.name === 'client',
65+ })),
66+ rsc({
67+ entries: {
68+ client: './src/framework/entry.browser.tsx',
69+ ssr: './src/framework/entry.ssr.tsx',
70+ rsc: './src/framework/entry.rsc.tsx',
71+ }
72+ }),
73+ ],
74+ })
75+ ` ,
76+ } ,
77+ } )
78+ } )
79+
80+ test . describe ( 'dev-react-compiler' , ( ) => {
81+ const f = useFixture ( { root, mode : 'dev' } )
82+ defineTest ( f )
83+
84+ test ( 'verify react compiler' , async ( { page } ) => {
85+ await page . goto ( f . url ( ) )
86+ await waitForHydration_ ( page )
87+ const res = await page . request . get ( f . url ( 'src/client.tsx' ) )
88+ expect ( await res . text ( ) ) . toContain ( 'react.memo_cache_sentinel' )
89+ } )
90+ } )
91+
92+ test . describe ( 'build-react-compiler' , ( ) => {
93+ const f = useFixture ( { root, mode : 'build' } )
94+ defineTest ( f )
95+ } )
96+ } )
97+
98+ test . describe ( ( ) => {
99+ const root = 'examples/e2e/temp/base'
100+
101+ test . beforeAll ( async ( ) => {
102+ await setupInlineFixture ( {
103+ src : 'examples/starter' ,
104+ dest : root ,
105+ files : {
106+ 'vite.config.ts' : /* js */ `
107+ import rsc from '@vitejs/plugin-rsc'
108+ import react from '@vitejs/plugin-react'
109+ import { defineConfig } from 'vite'
110+
111+ export default defineConfig({
112+ base: '/custom-base/',
113+ plugins: [
114+ react(),
115+ rsc({
116+ entries: {
117+ client: './src/framework/entry.browser.tsx',
118+ ssr: './src/framework/entry.ssr.tsx',
119+ rsc: './src/framework/entry.rsc.tsx',
120+ }
121+ }),
122+ ],
123+ })
124+ ` ,
125+ } ,
126+ } )
127+ } )
128+
129+ test . describe ( 'dev-base' , ( ) => {
130+ const f = useFixture ( { root, mode : 'dev' } )
131+ defineTest ( {
132+ ...f ,
133+ url : ( url ) => new URL ( url ?? './' , f . url ( './custom-base/' ) ) . href ,
134+ } )
135+ } )
136+
137+ test . describe ( 'build-base' , ( ) => {
138+ const f = useFixture ( { root, mode : 'build' } )
139+ defineTest ( {
140+ ...f ,
141+ url : ( url ) => new URL ( url ?? './' , f . url ( './custom-base/' ) ) . href ,
142+ } )
143+ } )
144+ } )
145+
45146function defineTest ( f : Fixture , variant ?: 'no-ssr' ) {
46147 const waitForHydration : typeof waitForHydration_ = ( page ) =>
47148 waitForHydration_ ( page , variant === 'no-ssr' ? '#root' : 'body' )
@@ -110,6 +211,24 @@ function defineTest(f: Fixture, variant?: 'no-ssr') {
110211 await page . getByRole ( 'button' , { name : 'Client Counter: 0' } ) . click ( )
111212 } )
112213
214+ test . describe ( ( ) => {
215+ test . skip ( f . mode === 'build' )
216+
217+ test ( 'server hmr' , async ( { page } ) => {
218+ await page . goto ( f . url ( ) )
219+ await waitForHydration ( page )
220+ await using _ = await expectNoReload ( page )
221+ await expect ( page . getByText ( 'Vite + RSC' ) ) . toBeVisible ( )
222+ const editor = f . createEditor ( 'src/root.tsx' )
223+ editor . edit ( ( s ) =>
224+ s . replace ( '<h1>Vite + RSC</h1>' , '<h1>Vite x RSC</h1>' ) ,
225+ )
226+ await expect ( page . getByText ( 'Vite x RSC' ) ) . toBeVisible ( )
227+ editor . reset ( )
228+ await expect ( page . getByText ( 'Vite + RSC' ) ) . toBeVisible ( )
229+ } )
230+ } )
231+
113232 test ( 'image assets' , async ( { page } ) => {
114233 await page . goto ( f . url ( ) )
115234 await waitForHydration ( page )
@@ -122,4 +241,25 @@ function defineTest(f: Fixture, variant?: 'no-ssr') {
122241 0 ,
123242 )
124243 } )
244+
245+ test ( 'css @js' , async ( { page } ) => {
246+ await page . goto ( f . url ( ) )
247+ await waitForHydration ( page )
248+ await expect ( page . locator ( '.read-the-docs' ) ) . toHaveCSS (
249+ 'color' ,
250+ 'rgb(136, 136, 136)' ,
251+ )
252+ } )
253+
254+ test . describe ( ( ) => {
255+ test . skip ( variant === 'no-ssr' )
256+
257+ testNoJs ( 'css @nojs' , async ( { page } ) => {
258+ await page . goto ( f . url ( ) )
259+ await expect ( page . locator ( '.read-the-docs' ) ) . toHaveCSS (
260+ 'color' ,
261+ 'rgb(136, 136, 136)' ,
262+ )
263+ } )
264+ } )
125265}
0 commit comments