@@ -11,6 +11,7 @@ import {
11
11
12
12
const fileSystem = {
13
13
'/src/pages/api.ts' : `export const GET = () => Response.json({ success: true })` ,
14
+ '/src/pages/dot.json.ts' : `export const GET = () => Response.json({ success: true })` ,
14
15
} ;
15
16
16
17
describe ( 'trailingSlash' , ( ) => {
@@ -24,6 +25,23 @@ describe('trailingSlash', () => {
24
25
trailingSlash : 'always' ,
25
26
output : 'server' ,
26
27
adapter : testAdapter ( ) ,
28
+ integrations : [
29
+ {
30
+ name : 'test' ,
31
+ hooks : {
32
+ 'astro:config:setup' : ( { injectRoute } ) => {
33
+ injectRoute ( {
34
+ pattern : '/injected' ,
35
+ entrypoint : './src/pages/api.ts' ,
36
+ } ) ;
37
+ injectRoute ( {
38
+ pattern : '/injected.json' ,
39
+ entrypoint : './src/pages/api.ts' ,
40
+ } ) ;
41
+ } ,
42
+ } ,
43
+ } ,
44
+ ] ,
27
45
} ) ;
28
46
container = await createContainer ( {
29
47
settings,
@@ -55,4 +73,47 @@ describe('trailingSlash', () => {
55
73
assert . equal ( html . includes ( `<span class="statusMessage">Not found</span>` ) , true ) ;
56
74
assert . equal ( res . statusCode , 404 ) ;
57
75
} ) ;
76
+
77
+ it ( 'should match an injected route when request has a trailing slash' , async ( ) => {
78
+ const { req, res, text } = createRequestAndResponse ( {
79
+ method : 'GET' ,
80
+ url : '/injected/' ,
81
+ } ) ;
82
+ container . handle ( req , res ) ;
83
+ const json = await text ( ) ;
84
+ assert . equal ( json , '{"success":true}' ) ;
85
+ } ) ;
86
+
87
+ it ( 'should NOT match an injected route when request lacks a trailing slash' , async ( ) => {
88
+ const { req, res, text } = createRequestAndResponse ( {
89
+ method : 'GET' ,
90
+ url : '/injected' ,
91
+ } ) ;
92
+ container . handle ( req , res ) ;
93
+ const html = await text ( ) ;
94
+ assert . equal ( html . includes ( `<span class="statusMessage">Not found</span>` ) , true ) ;
95
+ assert . equal ( res . statusCode , 404 ) ;
96
+ } ) ;
97
+
98
+ it ( 'should match the API route when request has a trailing slash, with a file extension' , async ( ) => {
99
+ const { req, res, text } = createRequestAndResponse ( {
100
+ method : 'GET' ,
101
+ url : '/dot.json/' ,
102
+ } ) ;
103
+ container . handle ( req , res ) ;
104
+ const json = await text ( ) ;
105
+ assert . equal ( json , '{"success":true}' ) ;
106
+ } ) ;
107
+
108
+ it ( 'should NOT match the API route when request lacks a trailing slash, with a file extension' , async ( ) => {
109
+ const { req, res, text } = createRequestAndResponse ( {
110
+ method : 'GET' ,
111
+ url : '/dot.json' ,
112
+ } ) ;
113
+ container . handle ( req , res ) ;
114
+ const html = await text ( ) ;
115
+ assert . equal ( html . includes ( `<span class="statusMessage">Not found</span>` ) , true ) ;
116
+ assert . equal ( res . statusCode , 404 ) ;
117
+ } ) ;
118
+
58
119
} ) ;
0 commit comments