@@ -15,12 +15,15 @@ const fileSystem = {
1515} ;
1616
1717describe ( 'trailingSlash' , ( ) => {
18+ let fixture ;
1819 let container ;
19- let settings ;
20+ let baseContainer ;
2021
2122 before ( async ( ) => {
22- const fixture = await createFixture ( fileSystem ) ;
23- settings = await createBasicSettings ( {
23+ fixture = await createFixture ( fileSystem ) ;
24+
25+ // Create the first container with trailingSlash: 'always'
26+ const settings = await createBasicSettings ( {
2427 root : fixture . path ,
2528 trailingSlash : 'always' ,
2629 output : 'server' ,
@@ -47,12 +50,44 @@ describe('trailingSlash', () => {
4750 settings,
4851 logger : defaultLogger ,
4952 } ) ;
53+
54+ // Create the second container with base path and trailingSlash: 'never'
55+ const baseSettings = await createBasicSettings ( {
56+ root : fixture . path ,
57+ trailingSlash : 'never' ,
58+ base : 'base' ,
59+ output : 'server' ,
60+ adapter : testAdapter ( ) ,
61+ integrations : [
62+ {
63+ name : 'test' ,
64+ hooks : {
65+ 'astro:config:setup' : ( { injectRoute } ) => {
66+ injectRoute ( {
67+ pattern : '/' ,
68+ entrypoint : './src/pages/api.ts' ,
69+ } ) ;
70+ injectRoute ( {
71+ pattern : '/injected' ,
72+ entrypoint : './src/pages/api.ts' ,
73+ } ) ;
74+ } ,
75+ } ,
76+ } ,
77+ ] ,
78+ } ) ;
79+ baseContainer = await createContainer ( {
80+ settings : baseSettings ,
81+ logger : defaultLogger ,
82+ } ) ;
5083 } ) ;
5184
5285 after ( async ( ) => {
5386 await container . close ( ) ;
87+ await baseContainer . close ( ) ;
5488 } ) ;
5589
90+ // Tests for trailingSlash: 'always'
5691 it ( 'should match the API route when request has a trailing slash' , async ( ) => {
5792 const { req, res, text } = createRequestAndResponse ( {
5893 method : 'GET' ,
@@ -124,4 +159,26 @@ describe('trailingSlash', () => {
124159 const json = await text ( ) ;
125160 assert . equal ( json , '{"success":true}' ) ;
126161 } ) ;
162+
163+ // Tests for trailingSlash: 'never' with base path
164+ it ( 'should not have trailing slash on root path when base is set and trailingSlash is never' , async ( ) => {
165+ const { req, res, text } = createRequestAndResponse ( {
166+ method : 'GET' ,
167+ url : '/base' ,
168+ } ) ;
169+ baseContainer . handle ( req , res ) ;
170+ const json = await text ( ) ;
171+ assert . equal ( json , '{"success":true}' ) ;
172+ } ) ;
173+
174+ it ( 'should not match root path with trailing slash when base is set and trailingSlash is never' , async ( ) => {
175+ const { req, res, text } = createRequestAndResponse ( {
176+ method : 'GET' ,
177+ url : '/base/' ,
178+ } ) ;
179+ baseContainer . handle ( req , res ) ;
180+ const html = await text ( ) ;
181+ assert . equal ( html . includes ( `<span class="statusMessage">Not found</span>` ) , true ) ;
182+ assert . equal ( res . statusCode , 404 ) ;
183+ } ) ;
127184} ) ;
0 commit comments