@@ -4,12 +4,12 @@ import testAdapter from './test-adapter.js';
4
4
import * as cheerio from 'cheerio' ;
5
5
6
6
describe ( '404 and 500 pages' , ( ) => {
7
- /** @type {import('./test-utils').Fixture } */
7
+ /** @type {import('./test-utils.js ').Fixture } */
8
8
let fixture ;
9
9
10
10
before ( async ( ) => {
11
11
fixture = await loadFixture ( {
12
- root : './fixtures/ssr-api-route-custom-404 /' ,
12
+ root : './fixtures/ssr-error-pages /' ,
13
13
output : 'server' ,
14
14
adapter : testAdapter ( ) ,
15
15
// test suite was authored when inlineStylesheets defaulted to never
@@ -18,8 +18,9 @@ describe('404 and 500 pages', () => {
18
18
} ) ;
19
19
20
20
describe ( 'Development' , ( ) => {
21
- /** @type {import('./test-utils').DevServer } */
21
+ /** @type {import('./test-utils.js ').DevServer } */
22
22
let devServer ;
23
+
23
24
before ( async ( ) => {
24
25
devServer = await fixture . startDevServer ( ) ;
25
26
} ) ;
@@ -39,12 +40,15 @@ describe('404 and 500 pages', () => {
39
40
} ) ;
40
41
41
42
describe ( 'Production' , ( ) => {
43
+ /** @type {import('./test-utils.js').App } */
44
+ let app ;
45
+
42
46
before ( async ( ) => {
43
47
await fixture . build ( { } ) ;
48
+ app = await fixture . loadTestAdapterApp ( ) ;
44
49
} ) ;
45
50
46
51
it ( '404 page returned when a route does not match' , async ( ) => {
47
- const app = await fixture . loadTestAdapterApp ( ) ;
48
52
const request = new Request ( 'http://example.com/some/fake/route' ) ;
49
53
const response = await app . render ( request ) ;
50
54
expect ( response . status ) . to . equal ( 404 ) ;
@@ -54,29 +58,26 @@ describe('404 and 500 pages', () => {
54
58
} ) ;
55
59
56
60
it ( '404 page returned when a route does not match and passing routeData' , async ( ) => {
57
- const app = await fixture . loadTestAdapterApp ( ) ;
58
61
const request = new Request ( 'http://example.com/some/fake/route' ) ;
59
62
const routeData = app . match ( request ) ;
60
- const response = await app . render ( request , routeData ) ;
63
+ const response = await app . render ( request , { routeData } ) ;
61
64
expect ( response . status ) . to . equal ( 404 ) ;
62
65
const html = await response . text ( ) ;
63
66
const $ = cheerio . load ( html ) ;
64
67
expect ( $ ( 'h1' ) . text ( ) ) . to . equal ( 'Something went horribly wrong!' ) ;
65
68
} ) ;
66
69
67
70
it ( '404 page returned when a route does not match and imports are included' , async ( ) => {
68
- const app = await fixture . loadTestAdapterApp ( ) ;
69
71
const request = new Request ( 'http://example.com/blog/fake/route' ) ;
70
72
const routeData = app . match ( request ) ;
71
- const response = await app . render ( request , routeData ) ;
73
+ const response = await app . render ( request , { routeData } ) ;
72
74
expect ( response . status ) . to . equal ( 404 ) ;
73
75
const html = await response . text ( ) ;
74
76
const $ = cheerio . load ( html ) ;
75
77
expect ( $ ( 'head link' ) ) . to . have . a . lengthOf ( 1 ) ;
76
78
} ) ;
77
79
78
80
it ( '404 page returned when there is an 404 response returned from route' , async ( ) => {
79
- const app = await fixture . loadTestAdapterApp ( ) ;
80
81
const request = new Request ( 'http://example.com/causes-404' ) ;
81
82
const response = await app . render ( request ) ;
82
83
expect ( response . status ) . to . equal ( 404 ) ;
@@ -86,7 +87,6 @@ describe('404 and 500 pages', () => {
86
87
} ) ;
87
88
88
89
it ( '500 page returned when there is an error' , async ( ) => {
89
- const app = await fixture . loadTestAdapterApp ( ) ;
90
90
const request = new Request ( 'http://example.com/causes-error' ) ;
91
91
const response = await app . render ( request ) ;
92
92
expect ( response . status ) . to . equal ( 500 ) ;
@@ -96,7 +96,6 @@ describe('404 and 500 pages', () => {
96
96
} ) ;
97
97
98
98
it ( 'Returns 404 when hitting an API route with the wrong method' , async ( ) => {
99
- const app = await fixture . loadTestAdapterApp ( ) ;
100
99
const request = new Request ( 'http://example.com/api/route' , {
101
100
method : 'PUT' ,
102
101
} ) ;
@@ -108,3 +107,54 @@ describe('404 and 500 pages', () => {
108
107
} ) ;
109
108
} ) ;
110
109
} ) ;
110
+
111
+ describe ( 'trailing slashes for error pages' , ( ) => {
112
+ /** @type {import('./test-utils.js').Fixture } */
113
+ let fixture ;
114
+
115
+ before ( async ( ) => {
116
+ fixture = await loadFixture ( {
117
+ root : './fixtures/ssr-error-pages/' ,
118
+ output : 'server' ,
119
+ adapter : testAdapter ( ) ,
120
+ trailingSlash : 'always'
121
+ } ) ;
122
+ } ) ;
123
+
124
+ describe ( 'Development' , ( ) => {
125
+ /** @type {import('./test-utils.js').DevServer } */
126
+ let devServer ;
127
+
128
+ before ( async ( ) => {
129
+ devServer = await fixture . startDevServer ( ) ;
130
+ } ) ;
131
+
132
+ it ( 'renders 404 page when a route does not match the request' , async ( ) => {
133
+ const response = await fixture . fetch ( '/ashbfjkasn' ) ;
134
+ expect ( response ) . to . deep . include ( { status : 404 } ) ;
135
+ const html = await response . text ( ) ;
136
+ expect ( html ) . to . not . be . empty ;
137
+ const $ = cheerio . load ( html ) ;
138
+ expect ( $ ( 'h1' ) . text ( ) ) . to . equal ( `Something went horribly wrong!` ) ;
139
+ } ) ;
140
+ } ) ;
141
+
142
+ describe ( 'Production' , ( ) => {
143
+ /** @type {import('./test-utils.js').App } */
144
+ let app ;
145
+
146
+ before ( async ( ) => {
147
+ await fixture . build ( { } ) ;
148
+ app = await fixture . loadTestAdapterApp ( ) ;
149
+ } ) ;
150
+
151
+ it ( 'renders 404 page when a route does not match the request' , async ( ) => {
152
+ const response = await app . render ( new Request ( 'http://example.com/ajksalscla' ) ) ;
153
+ expect ( response ) . to . deep . include ( { status : 404 } ) ;
154
+ const html = await response . text ( ) ;
155
+ expect ( html ) . to . not . be . empty ;
156
+ const $ = cheerio . load ( html ) ;
157
+ expect ( $ ( 'h1' ) . text ( ) ) . to . equal ( 'Something went horribly wrong!' ) ;
158
+ } )
159
+ } ) ;
160
+ } ) ;
0 commit comments