@@ -16,13 +16,25 @@ chai.use(dirtyChai)
16
16
chai . use ( chaiAsPromised )
17
17
const expect = chai . expect
18
18
19
+ function fixture ( file ) {
20
+ return path . resolve ( path . join ( __dirname , '..' , 'fixtures' , file ) )
21
+ }
22
+
23
+ function findMode ( file ) {
24
+ return fs . statSync ( fixture ( file ) ) . mode
25
+ }
26
+
27
+ function findMtime ( file ) {
28
+ return parseInt ( fs . statSync ( fixture ( file ) ) . mtimeMs / 1000 )
29
+ }
30
+
19
31
describe ( 'glob-source' , ( ) => {
20
32
it ( 'single file, relative path' , async function ( ) {
21
33
if ( ! isNode ) {
22
34
return this . skip ( )
23
35
}
24
36
25
- const result = await all ( globSource ( path . relative ( process . cwd ( ) , path . join ( __dirname , '..' , 'fixtures' , ' file-0.html') ) ) )
37
+ const result = await all ( globSource ( fixture ( ' file-0.html') ) )
26
38
27
39
expect ( result . length ) . to . equal ( 1 )
28
40
expect ( result [ 0 ] . path ) . to . equal ( '/file-0.html' )
@@ -33,7 +45,7 @@ describe('glob-source', () => {
33
45
return this . skip ( )
34
46
}
35
47
36
- const result = await all ( globSource ( path . resolve ( process . cwd ( ) , path . join ( __dirname , '..' , 'fixtures' , ' file-0.html') ) ) )
48
+ const result = await all ( globSource ( fixture ( ' file-0.html') ) )
37
49
38
50
expect ( result . length ) . to . equal ( 1 )
39
51
expect ( result [ 0 ] . path ) . to . equal ( '/file-0.html' )
@@ -44,7 +56,7 @@ describe('glob-source', () => {
44
56
return this . skip ( )
45
57
}
46
58
47
- const result = await all ( globSource ( path . relative ( process . cwd ( ) , path . join ( __dirname , '..' , 'fixtures' , ' dir') ) , {
59
+ const result = await all ( globSource ( fixture ( '/ dir') , {
48
60
recursive : true
49
61
} ) )
50
62
@@ -63,7 +75,7 @@ describe('glob-source', () => {
63
75
return this . skip ( )
64
76
}
65
77
66
- const result = await all ( globSource ( path . resolve ( process . cwd ( ) , path . join ( __dirname , '..' , 'fixtures' , ' dir') ) , {
78
+ const result = await all ( globSource ( fixture ( '/ dir') , {
67
79
recursive : true ,
68
80
hidden : true
69
81
} ) )
@@ -83,7 +95,7 @@ describe('glob-source', () => {
83
95
return this . skip ( )
84
96
}
85
97
86
- const result = await all ( globSource ( path . resolve ( process . cwd ( ) , path . join ( __dirname , '..' , 'fixtures' , ' dir') ) , {
98
+ const result = await all ( globSource ( fixture ( '/ dir') , {
87
99
recursive : true ,
88
100
ignore : [ '**/file-1.txt' ]
89
101
} ) )
@@ -102,8 +114,8 @@ describe('glob-source', () => {
102
114
}
103
115
104
116
const result = await all ( globSource ( [
105
- path . relative ( process . cwd ( ) , path . join ( __dirname , '..' , 'fixtures' , ' dir' , ' file-1.txt') ) ,
106
- path . relative ( process . cwd ( ) , path . join ( __dirname , '..' , 'fixtures' , ' dir' , ' file-2.js') )
117
+ fixture ( '/ dir/ file-1.txt') ,
118
+ fixture ( '/ dir/ file-2.js')
107
119
] ) )
108
120
109
121
expect ( result ) . to . have . lengthOf ( 2 )
@@ -116,40 +128,40 @@ describe('glob-source', () => {
116
128
return this . skip ( )
117
129
}
118
130
119
- await expect ( all ( globSource ( path . resolve ( process . cwd ( ) , path . join ( __dirname , '..' , 'fixtures' , ' dir') ) ) ) ) . to . be . rejectedWith ( / r e c u r s i v e o p t i o n n o t s e t / )
131
+ await expect ( all ( globSource ( fixture ( '/ dir') ) ) ) . to . be . rejectedWith ( / r e c u r s i v e o p t i o n n o t s e t / )
120
132
} )
121
133
122
134
it ( 'preserves mode for directories' , async function ( ) {
123
135
if ( ! isNode ) {
124
136
return this . skip ( )
125
137
}
126
138
127
- const result = await all ( globSource ( path . resolve ( path . join ( __dirname , '..' , 'fixtures' , ' dir') ) , {
139
+ const result = await all ( globSource ( fixture ( '/ dir') , {
128
140
preserveMode : true ,
129
141
recursive : true
130
142
} ) )
131
143
132
144
expect ( result ) . to . have . lengthOf ( 6 )
133
145
expect ( result ) . to . have . nested . property ( '[0].path' , '/dir' )
134
- expect ( result ) . to . have . nested . property ( '[0].mode' , fs . statSync ( path . resolve ( path . join ( __dirname , '..' , 'fixtures' , ' dir') ) ) . mode )
146
+ expect ( result ) . to . have . nested . property ( '[0].mode' , findMode ( '/ dir') )
135
147
expect ( result ) . to . have . nested . property ( '[1].path' , '/dir/file-1.txt' )
136
- expect ( result ) . to . have . nested . property ( '[1].mode' , fs . statSync ( path . resolve ( path . join ( __dirname , '..' , 'fixtures' , ' dir' , ' file-1.txt') ) ) . mode )
148
+ expect ( result ) . to . have . nested . property ( '[1].mode' , findMode ( '/ dir/ file-1.txt') )
137
149
expect ( result ) . to . have . nested . property ( '[2].path' , '/dir/file-2.js' )
138
- expect ( result ) . to . have . nested . property ( '[2].mode' , fs . statSync ( path . resolve ( path . join ( __dirname , '..' , 'fixtures' , ' dir' , ' file-2.js') ) ) . mode )
150
+ expect ( result ) . to . have . nested . property ( '[2].mode' , findMode ( '/ dir/ file-2.js') )
139
151
expect ( result ) . to . have . nested . property ( '[3].path' , '/dir/file-3.css' )
140
- expect ( result ) . to . have . nested . property ( '[3].mode' , fs . statSync ( path . resolve ( path . join ( __dirname , '..' , 'fixtures' , ' dir' , ' file-3.css') ) ) . mode )
152
+ expect ( result ) . to . have . nested . property ( '[3].mode' , findMode ( '/ dir/ file-3.css') )
141
153
expect ( result ) . to . have . nested . property ( '[4].path' , '/dir/nested-dir' )
142
- expect ( result ) . to . have . nested . property ( '[4].mode' , fs . statSync ( path . resolve ( path . join ( __dirname , '..' , 'fixtures' , ' dir' , ' nested-dir') ) ) . mode )
154
+ expect ( result ) . to . have . nested . property ( '[4].mode' , findMode ( '/ dir/ nested-dir') )
143
155
expect ( result ) . to . have . nested . property ( '[5].path' , '/dir/nested-dir/other.txt' )
144
- expect ( result ) . to . have . nested . property ( '[5].mode' , fs . statSync ( path . resolve ( path . join ( __dirname , '..' , 'fixtures' , ' dir' , ' nested-dir' , ' other.txt') ) ) . mode )
156
+ expect ( result ) . to . have . nested . property ( '[5].mode' , findMode ( '/ dir/ nested-dir/ other.txt') )
145
157
} )
146
158
147
159
it ( 'overrides mode for directories' , async function ( ) {
148
160
if ( ! isNode ) {
149
161
return this . skip ( )
150
162
}
151
163
152
- const result = await all ( globSource ( path . resolve ( process . cwd ( ) , path . join ( __dirname , '..' , 'fixtures' , ' dir') ) , {
164
+ const result = await all ( globSource ( fixture ( '/ dir') , {
153
165
recursive : true ,
154
166
mode : 5
155
167
} ) )
@@ -174,32 +186,32 @@ describe('glob-source', () => {
174
186
return this . skip ( )
175
187
}
176
188
177
- const result = await all ( globSource ( path . resolve ( path . join ( __dirname , '..' , 'fixtures' , ' dir') ) , {
189
+ const result = await all ( globSource ( fixture ( '/ dir') , {
178
190
preserveMtime : true ,
179
191
recursive : true
180
192
} ) )
181
193
182
194
expect ( result ) . to . have . lengthOf ( 6 )
183
195
expect ( result ) . to . have . nested . property ( '[0].path' , '/dir' )
184
- expect ( result ) . to . have . nested . property ( '[0].mtime' , parseInt ( fs . statSync ( path . resolve ( path . join ( __dirname , '..' , 'fixtures' , ' dir') ) ) . mtimeMs / 1000 ) )
196
+ expect ( result ) . to . have . nested . property ( '[0].mtime' , findMtime ( '/ dir') )
185
197
expect ( result ) . to . have . nested . property ( '[1].path' , '/dir/file-1.txt' )
186
- expect ( result ) . to . have . nested . property ( '[1].mtime' , parseInt ( fs . statSync ( path . resolve ( path . join ( __dirname , '..' , 'fixtures' , ' dir' , ' file-1.txt') ) ) . mtimeMs / 1000 ) )
198
+ expect ( result ) . to . have . nested . property ( '[1].mtime' , findMtime ( '/ dir/ file-1.txt') )
187
199
expect ( result ) . to . have . nested . property ( '[2].path' , '/dir/file-2.js' )
188
- expect ( result ) . to . have . nested . property ( '[2].mtime' , parseInt ( fs . statSync ( path . resolve ( path . join ( __dirname , '..' , 'fixtures' , ' dir' , ' file-2.js') ) ) . mtimeMs / 1000 ) )
200
+ expect ( result ) . to . have . nested . property ( '[2].mtime' , findMtime ( '/ dir/ file-2.js') )
189
201
expect ( result ) . to . have . nested . property ( '[3].path' , '/dir/file-3.css' )
190
- expect ( result ) . to . have . nested . property ( '[3].mtime' , parseInt ( fs . statSync ( path . resolve ( path . join ( __dirname , '..' , 'fixtures' , ' dir' , ' file-3.css') ) ) . mtimeMs / 1000 ) )
202
+ expect ( result ) . to . have . nested . property ( '[3].mtime' , findMtime ( '/ dir/ file-3.css') )
191
203
expect ( result ) . to . have . nested . property ( '[4].path' , '/dir/nested-dir' )
192
- expect ( result ) . to . have . nested . property ( '[4].mtime' , parseInt ( fs . statSync ( path . resolve ( path . join ( __dirname , '..' , 'fixtures' , ' dir' , ' nested-dir') ) ) . mtimeMs / 1000 ) )
204
+ expect ( result ) . to . have . nested . property ( '[4].mtime' , findMtime ( '/ dir/ nested-dir') )
193
205
expect ( result ) . to . have . nested . property ( '[5].path' , '/dir/nested-dir/other.txt' )
194
- expect ( result ) . to . have . nested . property ( '[5].mtime' , parseInt ( fs . statSync ( path . resolve ( path . join ( __dirname , '..' , 'fixtures' , ' dir' , ' nested-dir' , ' other.txt') ) ) . mtimeMs / 1000 ) )
206
+ expect ( result ) . to . have . nested . property ( '[5].mtime' , findMtime ( '/ dir/ nested-dir/ other.txt') )
195
207
} )
196
208
197
209
it ( 'overrides mtime for directories' , async function ( ) {
198
210
if ( ! isNode ) {
199
211
return this . skip ( )
200
212
}
201
213
202
- const result = await all ( globSource ( path . resolve ( process . cwd ( ) , path . join ( __dirname , '..' , 'fixtures' , ' dir') ) , {
214
+ const result = await all ( globSource ( fixture ( '/ dir') , {
203
215
recursive : true ,
204
216
mtime : 5
205
217
} ) )
0 commit comments