@@ -18,7 +18,7 @@ test('simple redirects', t => {
18
18
{ path : '/home' , to : '/' } ,
19
19
{ path : '/blog/my-post.php' , to : '/blog/my-post' } ,
20
20
{ path : '/blog/my-post-ads.php' , to : '/blog/my-post#ads' } ,
21
- { path : '/news' , to : '/blog' }
21
+ { path : '/news' , to : '/blog' } ,
22
22
] ,
23
23
result . success
24
24
)
@@ -38,7 +38,7 @@ test('redirects with status codes', t => {
38
38
{ path : '/home' , to : '/' , status : 301 } ,
39
39
{ path : '/my-redirect' , to : '/' , status : 302 } ,
40
40
{ path : '/pass-through' , to : '/' , status : 200 } ,
41
- { path : '/ecommerce' , to : '/store-closed' , status : 404 }
41
+ { path : '/ecommerce' , to : '/store-closed' , status : 404 } ,
42
42
] ,
43
43
result . success
44
44
)
@@ -55,7 +55,12 @@ test('redirects with parameter matches', t => {
55
55
[
56
56
{ path : '/' , to : '/news' , params : { page : 'news' } } ,
57
57
{ path : '/blog' , to : '/blog/:post_id' , params : { post : ':post_id' } } ,
58
- { path : '/' , to : '/about' , params : { _escaped_fragment_ : '/about' } , status : 301 }
58
+ {
59
+ path : '/' ,
60
+ to : '/about' ,
61
+ params : { _escaped_fragment_ : '/about' } ,
62
+ status : 301 ,
63
+ } ,
59
64
] ,
60
65
result . success
61
66
)
@@ -66,7 +71,14 @@ test('redirects with full hostname', t => {
66
71
67
72
const result = parser . parse ( source )
68
73
t . deepEqual (
69
- [ { host : 'hello.bitballoon.com' , scheme : 'http' , path : '/*' , to : 'http://www.hello.com/:splat' } ] ,
74
+ [
75
+ {
76
+ host : 'hello.bitballoon.com' ,
77
+ scheme : 'http' ,
78
+ path : '/*' ,
79
+ to : 'http://www.hello.com/:splat' ,
80
+ } ,
81
+ ] ,
70
82
result . success
71
83
)
72
84
} )
@@ -75,42 +87,94 @@ test('proxy instruction', t => {
75
87
const source = `/api/* https://api.bitballoon.com/* 200`
76
88
77
89
const result = parser . parse ( source )
78
- t . deepEqual ( [ { path : '/api/*' , to : 'https://api.bitballoon.com/*' , status : 200 , proxy : true } ] , result . success )
90
+ t . deepEqual (
91
+ [
92
+ {
93
+ path : '/api/*' ,
94
+ to : 'https://api.bitballoon.com/*' ,
95
+ status : 200 ,
96
+ proxy : true ,
97
+ } ,
98
+ ] ,
99
+ result . success
100
+ )
79
101
} )
80
102
81
103
test ( 'redirect with country conditions' , t => {
82
104
const source = `/ /china 302 Country=ch,tw`
83
105
84
106
const result = parser . parse ( source )
85
- t . deepEqual ( [ { path : '/' , to : '/china' , status : 302 , conditions : { Country : 'ch,tw' } } ] , result . success )
107
+ t . deepEqual (
108
+ [
109
+ {
110
+ path : '/' ,
111
+ to : '/china' ,
112
+ status : 302 ,
113
+ conditions : { Country : 'ch,tw' } ,
114
+ } ,
115
+ ] ,
116
+ result . success
117
+ )
86
118
} )
87
119
88
120
test ( 'redirect with country and language conditions' , t => {
89
121
const source = `/ /china 302 Country=il Language=en`
90
122
91
123
const result = parser . parse ( source )
92
- t . deepEqual ( [ { path : '/' , to : '/china' , status : 302 , conditions : { Country : 'il' , Language : 'en' } } ] , result . success )
124
+ t . deepEqual (
125
+ [
126
+ {
127
+ path : '/' ,
128
+ to : '/china' ,
129
+ status : 302 ,
130
+ conditions : { Country : 'il' , Language : 'en' } ,
131
+ } ,
132
+ ] ,
133
+ result . success
134
+ )
93
135
} )
94
136
95
137
test ( 'splat based redirect with no force instruction' , t => {
96
138
const source = `/* https://www.bitballoon.com/:splat 301`
97
139
98
140
const result = parser . parse ( source )
99
- t . deepEqual ( [ { path : '/*' , to : 'https://www.bitballoon.com/:splat' , status : 301 } ] , result . success )
141
+ t . deepEqual (
142
+ [ { path : '/*' , to : 'https://www.bitballoon.com/:splat' , status : 301 } ] ,
143
+ result . success
144
+ )
100
145
} )
101
146
102
147
test ( 'splat based redirect with force instruction' , t => {
103
148
const source = `/* https://www.bitballoon.com/:splat 301!`
104
149
105
150
const result = parser . parse ( source )
106
- t . deepEqual ( [ { path : '/*' , to : 'https://www.bitballoon.com/:splat' , status : 301 , force : true } ] , result . success )
151
+ t . deepEqual (
152
+ [
153
+ {
154
+ path : '/*' ,
155
+ to : 'https://www.bitballoon.com/:splat' ,
156
+ status : 301 ,
157
+ force : true ,
158
+ } ,
159
+ ] ,
160
+ result . success
161
+ )
107
162
} )
108
163
109
164
test ( 'redirect rule with equal' , t => {
110
165
const source = `/test https://www.bitballoon.com/test=hello 301`
111
166
112
167
const result = parser . parse ( source )
113
- t . deepEqual ( [ { path : '/test' , to : 'https://www.bitballoon.com/test=hello' , status : 301 } ] , result . success )
168
+ t . deepEqual (
169
+ [
170
+ {
171
+ path : '/test' ,
172
+ to : 'https://www.bitballoon.com/test=hello' ,
173
+ status : 301 ,
174
+ } ,
175
+ ] ,
176
+ result . success
177
+ )
114
178
} )
115
179
116
180
test ( 'some real world edge case rules' , t => {
@@ -123,18 +187,27 @@ test('some real world edge case rules', t => {
123
187
to : '/donate/usa?source=:source&email=:email' ,
124
188
params : { source : ':source' , email : ':email' } ,
125
189
status : 302 ,
126
- conditions : { Country : 'us' }
127
- }
128
- ]
190
+ conditions : { Country : 'us' } ,
191
+ } ,
192
+ ] ,
129
193
} ,
130
194
{
131
195
source : `/ https://origin.wework.com 200` ,
132
- result : [ { path : '/' , to : 'https://origin.wework.com' , status : 200 , proxy : true } ]
196
+ result : [
197
+ {
198
+ path : '/' ,
199
+ to : 'https://origin.wework.com' ,
200
+ status : 200 ,
201
+ proxy : true ,
202
+ } ,
203
+ ] ,
133
204
} ,
134
205
{
135
206
source : `/:lang/locations/* /locations/:splat 200` ,
136
- result : [ { path : '/:lang/locations/*' , to : '/locations/:splat' , status : 200 } ]
137
- }
207
+ result : [
208
+ { path : '/:lang/locations/*' , to : '/locations/:splat' , status : 200 } ,
209
+ ] ,
210
+ } ,
138
211
]
139
212
cases . forEach ( testcase => {
140
213
const result = parser . parse ( testcase . source )
@@ -203,10 +276,15 @@ test('complicated _redirects file', t => {
203
276
} )
204
277
205
278
test ( 'long _redirects file' , t => {
206
- const source = fs . readFileSync ( './test-files/redirects' , { encoding : 'utf-8' } )
279
+ const source = fs . readFileSync ( './test-files/redirects' , {
280
+ encoding : 'utf-8' ,
281
+ } )
207
282
208
283
const result = parser . parse ( source )
209
- t . deepEqual ( [ 640 , 734 , 917 , 918 , 919 , 920 , 987 ] , result . errors . map ( e => e . lineNum ) )
284
+ t . deepEqual (
285
+ [ 640 , 734 , 917 , 918 , 919 , 920 , 987 ] ,
286
+ result . errors . map ( e => e . lineNum )
287
+ )
210
288
t . truthy ( result . success . length > 0 )
211
289
} )
212
290
@@ -221,7 +299,7 @@ test('redirect with proxy signing', t => {
221
299
status : 200 ,
222
300
force : true ,
223
301
signed : 'API_SECRET' ,
224
- proxy : true
302
+ proxy : true ,
225
303
} ,
226
304
result . success [ 0 ]
227
305
)
@@ -249,7 +327,7 @@ https://www.ximble.com/* https://www.ximble.com/au/:splat 301! Country=au
249
327
to : 'https://www.ximble.com/au/:splat' ,
250
328
status : 301 ,
251
329
force : true ,
252
- conditions : { Country : 'au' }
330
+ conditions : { Country : 'au' } ,
253
331
} ,
254
332
result . success [ 0 ]
255
333
)
@@ -259,15 +337,32 @@ test('redirect role conditions', t => {
259
337
const source = `/admin/* /admin/:splat 200 Role=admin`
260
338
261
339
const result = parser . parse ( source )
262
- t . deepEqual ( [ { path : '/admin/*' , to : '/admin/:splat' , status : 200 , conditions : { Role : 'admin' } } ] , result . success )
340
+ t . deepEqual (
341
+ [
342
+ {
343
+ path : '/admin/*' ,
344
+ to : '/admin/:splat' ,
345
+ status : 200 ,
346
+ conditions : { Role : 'admin' } ,
347
+ } ,
348
+ ] ,
349
+ result . success
350
+ )
263
351
} )
264
352
265
353
test ( 'redirect with multiple roles' , t => {
266
354
const source = `/member/* /member/:splat 200 Role=admin,member`
267
355
268
356
const result = parser . parse ( source )
269
357
t . deepEqual (
270
- [ { path : '/member/*' , to : '/member/:splat' , status : 200 , conditions : { Role : 'admin,member' } } ] ,
358
+ [
359
+ {
360
+ path : '/member/*' ,
361
+ to : '/member/:splat' ,
362
+ status : 200 ,
363
+ conditions : { Role : 'admin,member' } ,
364
+ } ,
365
+ ] ,
271
366
result . success
272
367
)
273
368
} )
@@ -281,7 +376,7 @@ test('parse forward rule', t => {
281
376
t . deepEqual (
282
377
[
283
378
{ path : '/admin/*' , to : '/admin/:splat' , status : 200 } ,
284
- { path : '/admin/*' , to : '/admin/:splat' , status : 200 , force : true }
379
+ { path : '/admin/*' , to : '/admin/:splat' , status : 200 , force : true } ,
285
380
] ,
286
381
result . success
287
382
)
0 commit comments