@@ -65,61 +65,93 @@ describe('Astro.redirect', () => {
65
65
} ) ;
66
66
67
67
describe ( 'output: "static"' , ( ) => {
68
- before ( async ( ) => {
69
- process . env . STATIC_MODE = true ;
70
- fixture = await loadFixture ( {
71
- root : './fixtures/ssr-redirect/' ,
72
- output : 'static' ,
73
- experimental : {
74
- redirects : true ,
75
- } ,
76
- redirects : {
77
- '/one' : '/' ,
78
- '/two' : '/' ,
79
- '/blog/[...slug]' : '/articles/[...slug]' ,
80
- '/three' : {
81
- status : 302 ,
82
- destination : '/' ,
68
+ describe ( 'build' , ( ) => {
69
+ before ( async ( ) => {
70
+ process . env . STATIC_MODE = true ;
71
+ fixture = await loadFixture ( {
72
+ root : './fixtures/ssr-redirect/' ,
73
+ output : 'static' ,
74
+ experimental : {
75
+ redirects : true ,
83
76
} ,
84
- } ,
77
+ redirects : {
78
+ '/one' : '/' ,
79
+ '/two' : '/' ,
80
+ '/blog/[...slug]' : '/articles/[...slug]' ,
81
+ '/three' : {
82
+ status : 302 ,
83
+ destination : '/' ,
84
+ } ,
85
+ } ,
86
+ } ) ;
87
+ await fixture . build ( ) ;
88
+ } ) ;
89
+
90
+ it ( 'Includes the meta refresh tag in Astro.redirect pages' , async ( ) => {
91
+ const html = await fixture . readFile ( '/secret/index.html' ) ;
92
+ expect ( html ) . to . include ( 'http-equiv="refresh' ) ;
93
+ expect ( html ) . to . include ( 'url=/login' ) ;
94
+ } ) ;
95
+
96
+ it ( 'Includes the meta refresh tag in `redirect` config pages' , async ( ) => {
97
+ let html = await fixture . readFile ( '/one/index.html' ) ;
98
+ expect ( html ) . to . include ( 'http-equiv="refresh' ) ;
99
+ expect ( html ) . to . include ( 'url=/' ) ;
100
+
101
+ html = await fixture . readFile ( '/two/index.html' ) ;
102
+ expect ( html ) . to . include ( 'http-equiv="refresh' ) ;
103
+ expect ( html ) . to . include ( 'url=/' ) ;
104
+
105
+ html = await fixture . readFile ( '/three/index.html' ) ;
106
+ expect ( html ) . to . include ( 'http-equiv="refresh' ) ;
107
+ expect ( html ) . to . include ( 'url=/' ) ;
108
+ } ) ;
109
+
110
+ it ( 'Generates page for dynamic routes' , async ( ) => {
111
+ let html = await fixture . readFile ( '/blog/one/index.html' ) ;
112
+ expect ( html ) . to . include ( 'http-equiv="refresh' ) ;
113
+ expect ( html ) . to . include ( 'url=/articles/one' ) ;
114
+
115
+ html = await fixture . readFile ( '/blog/two/index.html' ) ;
116
+ expect ( html ) . to . include ( 'http-equiv="refresh' ) ;
117
+ expect ( html ) . to . include ( 'url=/articles/two' ) ;
118
+ } ) ;
119
+
120
+ it ( 'Generates redirect pages for redirects created by middleware' , async ( ) => {
121
+ let html = await fixture . readFile ( '/middleware-redirect/index.html' ) ;
122
+ expect ( html ) . to . include ( 'http-equiv="refresh' ) ;
123
+ expect ( html ) . to . include ( 'url=/' ) ;
85
124
} ) ;
86
- await fixture . build ( ) ;
87
- } ) ;
88
-
89
- it ( 'Includes the meta refresh tag in Astro.redirect pages' , async ( ) => {
90
- const html = await fixture . readFile ( '/secret/index.html' ) ;
91
- expect ( html ) . to . include ( 'http-equiv="refresh' ) ;
92
- expect ( html ) . to . include ( 'url=/login' ) ;
93
- } ) ;
94
-
95
- it ( 'Includes the meta refresh tag in `redirect` config pages' , async ( ) => {
96
- let html = await fixture . readFile ( '/one/index.html' ) ;
97
- expect ( html ) . to . include ( 'http-equiv="refresh' ) ;
98
- expect ( html ) . to . include ( 'url=/' ) ;
99
-
100
- html = await fixture . readFile ( '/two/index.html' ) ;
101
- expect ( html ) . to . include ( 'http-equiv="refresh' ) ;
102
- expect ( html ) . to . include ( 'url=/' ) ;
103
-
104
- html = await fixture . readFile ( '/three/index.html' ) ;
105
- expect ( html ) . to . include ( 'http-equiv="refresh' ) ;
106
- expect ( html ) . to . include ( 'url=/' ) ;
107
125
} ) ;
108
126
109
- it ( 'Generates page for dynamic routes' , async ( ) => {
110
- let html = await fixture . readFile ( '/blog/one/index.html' ) ;
111
- expect ( html ) . to . include ( 'http-equiv="refresh' ) ;
112
- expect ( html ) . to . include ( 'url=/articles/one' ) ;
113
-
114
- html = await fixture . readFile ( '/blog/two/index.html' ) ;
115
- expect ( html ) . to . include ( 'http-equiv="refresh' ) ;
116
- expect ( html ) . to . include ( 'url=/articles/two' ) ;
117
- } ) ;
127
+ describe ( 'dev' , ( ) => {
128
+ /** @type {import('./test-utils.js').DevServer } */
129
+ let devServer ;
130
+ before ( async ( ) => {
131
+ process . env . STATIC_MODE = true ;
132
+ fixture = await loadFixture ( {
133
+ root : './fixtures/ssr-redirect/' ,
134
+ output : 'static' ,
135
+ experimental : {
136
+ redirects : true ,
137
+ } ,
138
+ redirects : {
139
+ '/one' : '/' ,
140
+ } ,
141
+ } ) ;
142
+ devServer = await fixture . startDevServer ( ) ;
143
+ } ) ;
118
144
119
- it ( 'Generates redirect pages for redirects created by middleware' , async ( ) => {
120
- let html = await fixture . readFile ( '/middleware-redirect/index.html' ) ;
121
- expect ( html ) . to . include ( 'http-equiv="refresh' ) ;
122
- expect ( html ) . to . include ( 'url=/' ) ;
145
+ after ( async ( ) => {
146
+ await devServer . stop ( ) ;
147
+ } ) ;
148
+
149
+ it ( 'Returns 301' , async ( ) => {
150
+ let res = await fixture . fetch ( '/one' , {
151
+ redirect : 'manual'
152
+ } ) ;
153
+ expect ( res . status ) . to . equal ( 301 ) ;
154
+ } ) ;
123
155
} ) ;
124
156
} ) ;
125
157
0 commit comments