@@ -54,6 +54,8 @@ describe('dev', () => {
54
54
renderClientRootPageCorrectly ( { baseUrl, appPort, page } ) ) ;
55
55
it ( 'should render page with context correctly' , ( ) =>
56
56
renderPageWithContext ( { baseUrl, appPort, page } ) ) ;
57
+ it ( 'should support response api' , ( ) =>
58
+ supportResponseAPIForClientRoot ( { baseUrl, appPort, page } ) ) ;
57
59
} ) ;
58
60
59
61
describe ( 'server component root' , ( ) => {
@@ -62,6 +64,8 @@ describe('dev', () => {
62
64
renderServerRootPageCorrectly ( { baseUrl, appPort, page } ) ) ;
63
65
it ( 'should support client and server actions' , ( ) =>
64
66
supportServerAction ( { baseUrl, appPort, page } ) ) ;
67
+ it ( 'should support response api' , ( ) =>
68
+ supportResponseAPIForServerRoot ( { baseUrl, appPort, page } ) ) ;
65
69
} ) ;
66
70
} ) ;
67
71
@@ -110,6 +114,8 @@ describe('build', () => {
110
114
renderClientRootPageCorrectly ( { baseUrl, appPort, page } ) ) ;
111
115
it ( 'should render page with context correctly' , ( ) =>
112
116
renderPageWithContext ( { baseUrl, appPort, page } ) ) ;
117
+ it ( 'should support response api' , ( ) =>
118
+ supportResponseAPIForClientRoot ( { baseUrl, appPort, page } ) ) ;
113
119
} ) ;
114
120
115
121
describe ( 'server component root' , ( ) => {
@@ -118,6 +124,8 @@ describe('build', () => {
118
124
renderServerRootPageCorrectly ( { baseUrl, appPort, page } ) ) ;
119
125
it ( 'should support server action' , ( ) =>
120
126
supportServerAction ( { baseUrl, appPort, page } ) ) ;
127
+ it ( 'should support response api' , ( ) =>
128
+ supportResponseAPIForServerRoot ( { baseUrl, appPort, page } ) ) ;
121
129
} ) ;
122
130
} ) ;
123
131
@@ -181,3 +189,75 @@ async function supportServerAction({ baseUrl, appPort, page }: TestOptions) {
181
189
serverCount = await page . $eval ( '.server-count' , el => el . textContent ) ;
182
190
expect ( serverCount ) . toBe ( '1' ) ;
183
191
}
192
+
193
+ async function supportResponseAPIForServerRoot ( {
194
+ baseUrl,
195
+ appPort,
196
+ page,
197
+ } : TestOptions ) {
198
+ const headersRes = await fetch (
199
+ `http://127.0.0.1:${ appPort } /${ baseUrl } ?type=headers` ,
200
+ ) ;
201
+ expect ( headersRes . headers . get ( 'x-test' ) ) . toBe ( 'test-value' ) ;
202
+
203
+ // Test setStatus
204
+ const statusRes = await fetch (
205
+ `http://127.0.0.1:${ appPort } /${ baseUrl } ?type=status` ,
206
+ ) ;
207
+ expect ( statusRes . status ) . toBe ( 418 ) ;
208
+
209
+ // Test redirect with status code
210
+ const redirectRes = await fetch (
211
+ `http://127.0.0.1:${ appPort } /${ baseUrl } ?type=redirect` ,
212
+ { redirect : 'manual' } ,
213
+ ) ;
214
+ expect ( redirectRes . status ) . toBe ( 307 ) ;
215
+ expect ( redirectRes . headers . get ( 'location' ) ) . toBe ( '/client-component-root' ) ;
216
+
217
+ // Test redirect with init object
218
+ const redirectWithHeadersRes = await fetch (
219
+ `http://127.0.0.1:${ appPort } /${ baseUrl } ?type=redirect-with-headers` ,
220
+ { redirect : 'manual' } ,
221
+ ) ;
222
+ expect ( redirectWithHeadersRes . status ) . toBe ( 301 ) ;
223
+ expect ( redirectWithHeadersRes . headers . get ( 'location' ) ) . toBe (
224
+ '/client-component-root' ,
225
+ ) ;
226
+ expect ( redirectWithHeadersRes . headers . get ( 'x-redirect-test' ) ) . toBe ( 'test' ) ;
227
+ }
228
+
229
+ async function supportResponseAPIForClientRoot ( {
230
+ baseUrl,
231
+ appPort,
232
+ page,
233
+ } : TestOptions ) {
234
+ const headersRes = await fetch (
235
+ `http://127.0.0.1:${ appPort } /${ baseUrl } ?type=headers` ,
236
+ ) ;
237
+ expect ( headersRes . headers . get ( 'x-test' ) ) . toBe ( 'test-value' ) ;
238
+
239
+ // Test setStatus
240
+ const statusRes = await fetch (
241
+ `http://127.0.0.1:${ appPort } /${ baseUrl } ?type=status` ,
242
+ ) ;
243
+ expect ( statusRes . status ) . toBe ( 418 ) ;
244
+
245
+ // Test redirect with status code
246
+ const redirectRes = await fetch (
247
+ `http://127.0.0.1:${ appPort } /${ baseUrl } ?type=redirect` ,
248
+ { redirect : 'manual' } ,
249
+ ) ;
250
+ expect ( redirectRes . status ) . toBe ( 307 ) ;
251
+ expect ( redirectRes . headers . get ( 'location' ) ) . toBe ( '/server-component-root' ) ;
252
+
253
+ // Test redirect with init object
254
+ const redirectWithHeadersRes = await fetch (
255
+ `http://127.0.0.1:${ appPort } /${ baseUrl } ?type=redirect-with-headers` ,
256
+ { redirect : 'manual' } ,
257
+ ) ;
258
+ expect ( redirectWithHeadersRes . status ) . toBe ( 301 ) ;
259
+ expect ( redirectWithHeadersRes . headers . get ( 'location' ) ) . toBe (
260
+ '/server-component-root' ,
261
+ ) ;
262
+ expect ( redirectWithHeadersRes . headers . get ( 'x-redirect-test' ) ) . toBe ( 'test' ) ;
263
+ }
0 commit comments