1
1
import * as path from 'path' ;
2
2
import * as assert from 'assert' ;
3
- import manifest_data from '../../../src/core/create_manifest_data' ;
3
+ import create_manifest_data from '../../../src/core/create_manifest_data' ;
4
4
5
5
describe ( 'manifest_data' , ( ) => {
6
6
it ( 'creates routes' , ( ) => {
7
- const { components, pages, server_routes } = manifest_data ( path . join ( __dirname , 'samples/basic' ) ) ;
7
+ const { components, pages, server_routes } = create_manifest_data ( path . join ( __dirname , 'samples/basic' ) ) ;
8
8
9
9
const index = { name : 'index' , file : 'index.html' } ;
10
10
const about = { name : 'about' , file : 'about.html' } ;
@@ -68,7 +68,7 @@ describe('manifest_data', () => {
68
68
} ) ;
69
69
70
70
it ( 'encodes invalid characters' , ( ) => {
71
- const { components, pages } = manifest_data ( path . join ( __dirname , 'samples/encoding' ) ) ;
71
+ const { components, pages } = create_manifest_data ( path . join ( __dirname , 'samples/encoding' ) ) ;
72
72
73
73
// had to remove ? and " because windows
74
74
@@ -90,7 +90,7 @@ describe('manifest_data', () => {
90
90
} ) ;
91
91
92
92
it ( 'allows regex qualifiers' , ( ) => {
93
- const { pages } = manifest_data ( path . join ( __dirname , 'samples/qualifiers' ) ) ;
93
+ const { pages } = create_manifest_data ( path . join ( __dirname , 'samples/qualifiers' ) ) ;
94
94
95
95
assert . deepEqual ( pages . map ( p => p . pattern ) , [
96
96
/ ^ \/ ( [ 0 - 9 - a- z ] { 3 , } ) \/ ? $ / ,
@@ -100,7 +100,7 @@ describe('manifest_data', () => {
100
100
} ) ;
101
101
102
102
it ( 'sorts routes correctly' , ( ) => {
103
- const { pages } = manifest_data ( path . join ( __dirname , 'samples/sorting' ) ) ;
103
+ const { pages } = create_manifest_data ( path . join ( __dirname , 'samples/sorting' ) ) ;
104
104
105
105
assert . deepEqual ( pages . map ( p => p . parts . map ( part => part && part . component . file ) ) , [
106
106
[ 'index.html' ] ,
@@ -116,7 +116,7 @@ describe('manifest_data', () => {
116
116
} ) ;
117
117
118
118
it ( 'ignores files and directories with leading underscores' , ( ) => {
119
- const { server_routes } = manifest_data ( path . join ( __dirname , 'samples/hidden-underscore' ) ) ;
119
+ const { server_routes } = create_manifest_data ( path . join ( __dirname , 'samples/hidden-underscore' ) ) ;
120
120
121
121
assert . deepEqual ( server_routes . map ( r => r . file ) , [
122
122
'index.js' ,
@@ -125,7 +125,7 @@ describe('manifest_data', () => {
125
125
} ) ;
126
126
127
127
it ( 'ignores files and directories with leading dots except .well-known' , ( ) => {
128
- const { server_routes } = manifest_data ( path . join ( __dirname , 'samples/hidden-dot' ) ) ;
128
+ const { server_routes } = create_manifest_data ( path . join ( __dirname , 'samples/hidden-dot' ) ) ;
129
129
130
130
assert . deepEqual ( server_routes . map ( r => r . file ) , [
131
131
'.well-known/dnt-policy.txt.js'
@@ -134,24 +134,35 @@ describe('manifest_data', () => {
134
134
135
135
it ( 'fails on clashes' , ( ) => {
136
136
assert . throws ( ( ) => {
137
- const { pages } = manifest_data ( path . join ( __dirname , 'samples/clash-pages' ) ) ;
137
+ const { pages } = create_manifest_data ( path . join ( __dirname , 'samples/clash-pages' ) ) ;
138
138
} , / T h e \[ b a r \] \/ i n d e x \. h t m l a n d \[ f o o \] \. h t m l p a g e s c l a s h / ) ;
139
139
140
140
assert . throws ( ( ) => {
141
- const { server_routes } = manifest_data ( path . join ( __dirname , 'samples/clash-routes' ) ) ;
141
+ const { server_routes } = create_manifest_data ( path . join ( __dirname , 'samples/clash-routes' ) ) ;
142
142
console . log ( server_routes ) ;
143
143
} , / T h e \[ b a r \] \/ i n d e x \. j s a n d \[ f o o \] \. j s r o u t e s c l a s h / ) ;
144
144
} ) ;
145
145
146
146
it ( 'fails if dynamic params are not separated' , ( ) => {
147
147
assert . throws ( ( ) => {
148
- manifest_data ( path . join ( __dirname , 'samples/invalid-params' ) ) ;
148
+ create_manifest_data ( path . join ( __dirname , 'samples/invalid-params' ) ) ;
149
149
} , / I n v a l i d r o u t e \[ f o o \] \[ b a r \] \. j s — p a r a m e t e r s m u s t b e s e p a r a t e d / ) ;
150
150
} ) ;
151
151
152
152
it ( 'errors when trying to use reserved characters in route regexp' , ( ) => {
153
153
assert . throws ( ( ) => {
154
- manifest_data ( path . join ( __dirname , 'samples/invalid-qualifier' ) ) ;
154
+ create_manifest_data ( path . join ( __dirname , 'samples/invalid-qualifier' ) ) ;
155
155
} , / I n v a l i d r o u t e \[ f o o \( \[ a - z \] \( \[ 0 - 9 \] \) \) \] .j s — c a n n o t u s e \( , \) , \? o r \: i n r o u t e q u a l i f i e r s / ) ;
156
156
} ) ;
157
+
158
+ it ( 'ignores things that look like lockfiles' , ( ) => {
159
+ const { server_routes } = create_manifest_data ( path . join ( __dirname , 'samples/lockfiles' ) ) ;
160
+
161
+ assert . deepEqual ( server_routes , [ {
162
+ file : 'foo.js' ,
163
+ name : 'route_foo' ,
164
+ params : [ ] ,
165
+ pattern : / ^ \/ f o o $ /
166
+ } ] ) ;
167
+ } ) ;
157
168
} ) ;
0 commit comments