@@ -314,7 +314,7 @@ describe('Middleware', () => {
314
314
} ) ;
315
315
} ) ;
316
316
317
- describe ( 'Runtime error' , ( ) => {
317
+ describe ( 'Runtime error, default 500 ' , ( ) => {
318
318
/** @type {import('./test-utils').Fixture } */
319
319
let fixture ;
320
320
let devServer ;
@@ -330,10 +330,83 @@ describe('Runtime error', () => {
330
330
await devServer . stop ( ) ;
331
331
} ) ;
332
332
333
- it ( 'should render the index page when navigating /reroute ' , async ( ) => {
334
- const html = await fixture . fetch ( '/errors/from' ) . then ( ( res ) => res . text ( ) ) ;
333
+ it ( 'should return a 500 status code, but not render the custom 500' , async ( ) => {
334
+ const response = await fixture . fetch ( '/errors/from' ) ;
335
+ assert . equal ( response . status , 500 ) ;
336
+ const text = await response . text ( ) ;
337
+ assert . match ( text , / @ v i t e \/ c l i e n t / ) ;
338
+ } ) ;
339
+ } ) ;
340
+
341
+ describe ( 'Runtime error in SSR, default 500' , ( ) => {
342
+ /** @type {import('./test-utils').Fixture } */
343
+ let fixture ;
344
+ let app ;
345
+
346
+ before ( async ( ) => {
347
+ fixture = await loadFixture ( {
348
+ root : './fixtures/rewrite-runtime-error/' ,
349
+ output : 'server' ,
350
+ adapter : testAdapter ( ) ,
351
+ } ) ;
352
+ await fixture . build ( ) ;
353
+ app = await fixture . loadTestAdapterApp ( ) ;
354
+ } ) ;
355
+
356
+ it ( 'should return a 500 status code, but not render the custom 500' , async ( ) => {
357
+ const request = new Request ( 'http://example.com/errors/from' ) ;
358
+ const response = await app . render ( request ) ;
359
+ const text = await response . text ( ) ;
360
+ assert . equal ( text , '' ) ;
361
+ } ) ;
362
+ } ) ;
363
+
364
+ describe ( 'Runtime error in dev, custom 500' , ( ) => {
365
+ /** @type {import('./test-utils').Fixture } */
366
+ let fixture ;
367
+ let devServer ;
368
+
369
+ before ( async ( ) => {
370
+ fixture = await loadFixture ( {
371
+ root : './fixtures/rewrite-runtime-error-custom500/' ,
372
+ } ) ;
373
+ devServer = await fixture . startDevServer ( ) ;
374
+ } ) ;
375
+
376
+ after ( async ( ) => {
377
+ await devServer . stop ( ) ;
378
+ } ) ;
379
+
380
+ it ( 'should render the custom 500 when rewriting a page that throws an error' , async ( ) => {
381
+ const response = await fixture . fetch ( '/errors/start' ) ;
382
+ assert . equal ( response . status , 500 ) ;
383
+ const html = await response . text ( ) ;
384
+ assert . match ( html , / I a m t h e c u s t o m 5 0 0 / ) ;
385
+ } ) ;
386
+ } ) ;
387
+
388
+ describe ( 'Runtime error in SSR, custom 500' , ( ) => {
389
+ /** @type {import('./test-utils').Fixture } */
390
+ let fixture ;
391
+ let app ;
392
+
393
+ before ( async ( ) => {
394
+ fixture = await loadFixture ( {
395
+ root : './fixtures/rewrite-runtime-error-custom500/' ,
396
+ output : 'server' ,
397
+ adapter : testAdapter ( ) ,
398
+ } ) ;
399
+ await fixture . build ( ) ;
400
+ app = await fixture . loadTestAdapterApp ( ) ;
401
+ } ) ;
402
+
403
+ it ( 'should render the custom 500 when rewriting a page that throws an error' , async ( ) => {
404
+ const request = new Request ( 'http://example.com/errors/start' ) ;
405
+ const response = await app . render ( request ) ;
406
+ const html = await response . text ( ) ;
407
+
335
408
const $ = cheerioLoad ( html ) ;
336
409
337
- assert . equal ( $ ( 'title ' ) . text ( ) , 'Error ' ) ;
410
+ assert . equal ( $ ( 'h1 ' ) . text ( ) , 'I am the custom 500 ' ) ;
338
411
} ) ;
339
412
} ) ;
0 commit comments