@@ -8,6 +8,8 @@ describe('Astro Global', () => {
88 before ( async ( ) => {
99 fixture = await loadFixture ( {
1010 root : './fixtures/astro-global/' ,
11+ site : 'https://mysite.dev/' ,
12+ base : '/blog' ,
1113 } ) ;
1214 } ) ;
1315
@@ -85,3 +87,74 @@ describe('Astro Global', () => {
8587 } ) ;
8688 } ) ;
8789} ) ;
90+
91+ describe ( 'Astro Global Defaults' , ( ) => {
92+ let fixture ;
93+
94+ before ( async ( ) => {
95+ fixture = await loadFixture ( {
96+ root : './fixtures/astro-global/' ,
97+ } ) ;
98+ } ) ;
99+
100+ describe ( 'dev' , ( ) => {
101+ let devServer ;
102+ let $ ;
103+
104+ before ( async ( ) => {
105+ devServer = await fixture . startDevServer ( ) ;
106+ const html = await fixture . fetch ( '/blog/?foo=42' ) . then ( ( res ) => res . text ( ) ) ;
107+ $ = cheerio . load ( html ) ;
108+ } ) ;
109+
110+ after ( async ( ) => {
111+ await devServer . stop ( ) ;
112+ } ) ;
113+
114+ it ( 'Astro.request.url' , async ( ) => {
115+ expect ( $ ( '#pathname' ) . text ( ) ) . to . equal ( '' ) ;
116+ expect ( $ ( '#searchparams' ) . text ( ) ) . to . equal ( '' ) ;
117+ expect ( $ ( '#child-pathname' ) . text ( ) ) . to . equal ( '' ) ;
118+ expect ( $ ( '#nested-child-pathname' ) . text ( ) ) . to . equal ( '' ) ;
119+ } ) ;
120+ } ) ;
121+
122+ describe ( 'build' , ( ) => {
123+ before ( async ( ) => {
124+ await fixture . build ( ) ;
125+ } ) ;
126+
127+ it ( 'Astro.request.url' , async ( ) => {
128+ const html = await fixture . readFile ( '/index.html' ) ;
129+ const $ = cheerio . load ( html ) ;
130+
131+ expect ( $ ( '#pathname' ) . text ( ) ) . to . equal ( '/' ) ;
132+ expect ( $ ( '#searchparams' ) . text ( ) ) . to . equal ( '{}' ) ;
133+ expect ( $ ( '#child-pathname' ) . text ( ) ) . to . equal ( '/' ) ;
134+ expect ( $ ( '#nested-child-pathname' ) . text ( ) ) . to . equal ( '/' ) ;
135+ } ) ;
136+
137+ it ( 'Astro.canonicalURL' , async ( ) => {
138+ // given a URL, expect the following canonical URL
139+ const canonicalURLs = {
140+ '/index.html' : / h t t p : \/ \/ l o c a l h o s t : \d + \/ / ,
141+ '/post/post/index.html' : / h t t p : \/ \/ l o c a l h o s t : \d + \/ p o s t \/ p o s t \/ / ,
142+ '/posts/1/index.html' : / h t t p : \/ \/ l o c a l h o s t : \d + \/ p o s t s \/ / ,
143+ '/posts/2/index.html' : / h t t p : \/ \/ l o c a l h o s t : \d + \/ p o s t s \/ 2 \/ / ,
144+ } ;
145+
146+ for ( const [ url , canonicalURL ] of Object . entries ( canonicalURLs ) ) {
147+ const html = await fixture . readFile ( url ) ;
148+
149+ const $ = cheerio . load ( html ) ;
150+ expect ( $ ( 'link[rel="canonical"]' ) . attr ( 'href' ) ) . to . match ( canonicalURL ) ;
151+ }
152+ } ) ;
153+
154+ it ( 'Astro.site' , async ( ) => {
155+ const html = await fixture . readFile ( '/index.html' ) ;
156+ const $ = cheerio . load ( html ) ;
157+ expect ( $ ( '#site' ) . attr ( 'href' ) ) . to . match ( / h t t p : \/ \/ l o c a l h o s t : \d + \/ / ) ;
158+ } ) ;
159+ } ) ;
160+ } ) ;
0 commit comments