@@ -6,22 +6,16 @@ import { implementations, js, setupRscTest, validateRSCHtml } from "./utils";
66test . use ( { javaScriptEnabled : false } ) ;
77
88implementations . forEach ( ( implementation ) => {
9- let stop : ( ) => void ;
10-
11- test . afterEach ( ( ) => {
12- stop ?.( ) ;
13- } ) ;
14-
159 test . describe ( `RSC nojs (${ implementation . name } )` , ( ) => {
16- test ( "Supports React Server Functions side-effect redirect headers for document requests" , async ( {
17- page,
18- } , { project } ) => {
19- test . skip (
20- implementation . name === "parcel" || project . name !== "chromium" ,
21- "TODO: figure out why parcel isn't working here" ,
22- ) ;
10+ let port : number ;
11+ let stop : ( ) => void ;
2312
24- let port = await getPort ( ) ;
13+ test . afterAll ( ( ) => {
14+ stop ?.( ) ;
15+ } ) ;
16+
17+ test . beforeAll ( async ( ) => {
18+ port = await getPort ( ) ;
2519 stop = await setupRscTest ( {
2620 implementation,
2721 port,
@@ -34,6 +28,10 @@ implementations.forEach((implementation) => {
3428 redirect("/?redirected=true", { headers: { "x-test": "test" } });
3529 return "redirected";
3630 }
31+
32+ export async function incrementAction(prev) {
33+ return prev + 1;
34+ }
3735 ` ,
3836 "src/routes/home.client.tsx" : js `
3937 "use client";
@@ -47,7 +45,7 @@ implementations.forEach((implementation) => {
4745 "src/routes/home.tsx" : js `
4846 "use client";
4947 import {useActionState} from "react";
50- import { redirectAction } from "./home.actions";
48+ import { redirectAction, incrementAction } from "./home.actions";
5149 import { Counter } from "./home.client";
5250
5351 export default function HomeRoute(props) {
@@ -61,12 +59,34 @@ implementations.forEach((implementation) => {
6159 </form>
6260 {state && <div data-testid="state">{state}</div>}
6361 <Counter />
62+ <TestActionState />
6463 </div>
6564 );
6665 }
66+
67+ function TestActionState() {
68+ const [state, action] = useActionState(incrementAction, 0);
69+ return (
70+ <form action={action}>
71+ <button type="submit" data-action-state-increment-submit>
72+ action-state-increment
73+ </button>
74+ <div data-action-state-increment-result>{state}</div>
75+ </form>
76+ );
77+ }
6778 ` ,
6879 } ,
6980 } ) ;
81+ } ) ;
82+
83+ test ( "Supports React Server Functions side-effect redirect headers for document requests" , async ( {
84+ page,
85+ } , { project } ) => {
86+ test . skip (
87+ implementation . name === "parcel" || project . name !== "chromium" ,
88+ "TODO: figure out why parcel isn't working here" ,
89+ ) ;
7090
7191 await page . goto ( `http://localhost:${ port } /` ) ;
7292
@@ -89,5 +109,25 @@ implementations.forEach((implementation) => {
89109 // Ensure this is using RSC
90110 validateRSCHtml ( await page . content ( ) ) ;
91111 } ) ;
112+
113+ test ( "Supports form state without JS" , async ( { page } , { project } ) => {
114+ test . skip (
115+ implementation . name === "parcel" || project . name !== "chromium" ,
116+ "TODO: figure out why parcel isn't working here" ,
117+ ) ;
118+
119+ await page . goto ( `http://localhost:${ port } /` ) ;
120+
121+ await expect (
122+ page . locator ( "[data-action-state-increment-result]" ) ,
123+ ) . toHaveText ( "0" ) ;
124+ await page . click ( "[data-action-state-increment-submit]" ) ;
125+ await expect (
126+ page . locator ( "[data-action-state-increment-result]" ) ,
127+ ) . toHaveText ( "1" ) ;
128+
129+ // Ensure this is using RSC
130+ validateRSCHtml ( await page . content ( ) ) ;
131+ } ) ;
92132 } ) ;
93133} ) ;
0 commit comments