@@ -2,7 +2,7 @@ import fs from 'fs';
2
2
import util from 'util' ;
3
3
import path from 'path' ;
4
4
import test from 'ava' ;
5
- import m from '.' ;
5
+ import globby from '.' ;
6
6
7
7
const cwd = process . cwd ( ) ;
8
8
const tmp = 'tmp' ;
@@ -18,96 +18,102 @@ test.before(() => {
18
18
if ( ! fs . existsSync ( tmp ) ) {
19
19
fs . mkdirSync ( tmp ) ;
20
20
}
21
- fixture . forEach ( fs . writeFileSync . bind ( fs ) ) ;
22
- fixture . forEach ( x => fs . writeFileSync ( path . join ( __dirname , tmp , x ) ) ) ;
21
+
22
+ for ( const element of fixture ) {
23
+ fs . writeFileSync ( element ) ;
24
+ fs . writeFileSync ( path . join ( __dirname , tmp , element ) ) ;
25
+ }
23
26
} ) ;
24
27
25
28
test . after ( ( ) => {
26
- fixture . forEach ( fs . unlinkSync . bind ( fs ) ) ;
27
- fixture . forEach ( x => fs . unlinkSync ( path . join ( __dirname , tmp , x ) ) ) ;
29
+ for ( const element of fixture ) {
30
+ fs . unlinkSync ( element ) ;
31
+ fs . unlinkSync ( path . join ( __dirname , tmp , element ) ) ;
32
+ }
33
+
28
34
fs . rmdirSync ( tmp ) ;
29
35
} ) ;
30
36
31
37
test ( 'glob - async' , async t => {
32
- t . deepEqual ( await m ( '*.tmp' ) , [ 'a.tmp' , 'b.tmp' , 'c.tmp' , 'd.tmp' , 'e.tmp' ] ) ;
38
+ t . deepEqual ( ( await globby ( '*.tmp' ) ) . sort ( ) , [ 'a.tmp' , 'b.tmp' , 'c.tmp' , 'd.tmp' , 'e.tmp' ] ) ;
33
39
} ) ;
34
40
35
41
test ( 'glob - async - multiple file paths' , t => {
36
- t . deepEqual ( m . sync ( [ 'a.tmp' , 'b.tmp' ] ) , [ 'a.tmp' , 'b.tmp' ] ) ;
42
+ t . deepEqual ( globby . sync ( [ 'a.tmp' , 'b.tmp' ] ) , [ 'a.tmp' , 'b.tmp' ] ) ;
37
43
} ) ;
38
44
39
45
test ( 'glob with multiple patterns - async' , async t => {
40
- t . deepEqual ( await m ( [ 'a.tmp' , '*.tmp' , '!{c,d,e}.tmp' ] ) , [ 'a.tmp' , 'b.tmp' ] ) ;
46
+ t . deepEqual ( await globby ( [ 'a.tmp' , '*.tmp' , '!{c,d,e}.tmp' ] ) , [ 'a.tmp' , 'b.tmp' ] ) ;
41
47
} ) ;
42
48
43
49
test ( 'respect patterns order - async' , async t => {
44
- t . deepEqual ( await m ( [ '!*.tmp' , 'a.tmp' ] ) , [ 'a.tmp' ] ) ;
50
+ t . deepEqual ( await globby ( [ '!*.tmp' , 'a.tmp' ] ) , [ 'a.tmp' ] ) ;
45
51
} ) ;
46
52
47
53
test ( 'respect patterns order - sync' , t => {
48
- t . deepEqual ( m . sync ( [ '!*.tmp' , 'a.tmp' ] ) , [ 'a.tmp' ] ) ;
54
+ t . deepEqual ( globby . sync ( [ '!*.tmp' , 'a.tmp' ] ) , [ 'a.tmp' ] ) ;
49
55
} ) ;
50
56
51
57
test ( 'glob - sync' , t => {
52
- t . deepEqual ( m . sync ( '*.tmp' ) , [ 'a.tmp' , 'b.tmp' , 'c.tmp' , 'd.tmp' , 'e.tmp' ] ) ;
53
- t . deepEqual ( m . sync ( [ 'a.tmp' , '*.tmp' , '!{c,d,e}.tmp' ] ) , [ 'a.tmp' , 'b.tmp' ] ) ;
54
- t . deepEqual ( m . sync ( [ '!*.tmp' , 'a.tmp' ] ) , [ 'a.tmp' ] ) ;
58
+ t . deepEqual ( globby . sync ( '*.tmp' ) , [ 'a.tmp' , 'b.tmp' , 'c.tmp' , 'd.tmp' , 'e.tmp' ] ) ;
59
+ t . deepEqual ( globby . sync ( [ 'a.tmp' , '*.tmp' , '!{c,d,e}.tmp' ] ) , [ 'a.tmp' , 'b.tmp' ] ) ;
60
+ t . deepEqual ( globby . sync ( [ '!*.tmp' , 'a.tmp' ] ) , [ 'a.tmp' ] ) ;
55
61
} ) ;
56
62
57
63
test ( 'glob - sync - multiple file paths' , t => {
58
- t . deepEqual ( m . sync ( [ 'a.tmp' , 'b.tmp' ] ) , [ 'a.tmp' , 'b.tmp' ] ) ;
64
+ t . deepEqual ( globby . sync ( [ 'a.tmp' , 'b.tmp' ] ) , [ 'a.tmp' , 'b.tmp' ] ) ;
59
65
} ) ;
60
66
61
67
test ( 'return [] for all negative patterns - sync' , t => {
62
- t . deepEqual ( m . sync ( [ '!a.tmp' , '!b.tmp' ] ) , [ ] ) ;
68
+ t . deepEqual ( globby . sync ( [ '!a.tmp' , '!b.tmp' ] ) , [ ] ) ;
63
69
} ) ;
64
70
65
71
test ( 'return [] for all negative patterns - async' , async t => {
66
- t . deepEqual ( await m ( [ '!a.tmp' , '!b.tmp' ] ) , [ ] ) ;
72
+ t . deepEqual ( await globby ( [ '!a.tmp' , '!b.tmp' ] ) , [ ] ) ;
67
73
} ) ;
68
74
69
75
test ( 'cwd option' , t => {
70
76
process . chdir ( tmp ) ;
71
- t . deepEqual ( m . sync ( '*.tmp' , { cwd} ) , [ 'a.tmp' , 'b.tmp' , 'c.tmp' , 'd.tmp' , 'e.tmp' ] ) ;
72
- t . deepEqual ( m . sync ( [ 'a.tmp' , '*.tmp' , '!{c,d,e}.tmp' ] , { cwd} ) , [ 'a.tmp' , 'b.tmp' ] ) ;
77
+ t . deepEqual ( globby . sync ( '*.tmp' , { cwd} ) , [ 'a.tmp' , 'b.tmp' , 'c.tmp' , 'd.tmp' , 'e.tmp' ] ) ;
78
+ t . deepEqual ( globby . sync ( [ 'a.tmp' , '*.tmp' , '!{c,d,e}.tmp' ] , { cwd} ) , [ 'a.tmp' , 'b.tmp' ] ) ;
73
79
process . chdir ( cwd ) ;
74
80
} ) ;
75
81
76
82
test ( 'don\'t mutate the options object - async' , async t => {
77
- await m ( [ '*.tmp' , '!b.tmp' ] , Object . freeze ( { ignore : Object . freeze ( [ ] ) } ) ) ;
83
+ await globby ( [ '*.tmp' , '!b.tmp' ] , Object . freeze ( { ignore : Object . freeze ( [ ] ) } ) ) ;
78
84
t . pass ( ) ;
79
85
} ) ;
80
86
81
87
test ( 'don\'t mutate the options object - sync' , t => {
82
- m . sync ( [ '*.tmp' , '!b.tmp' ] , Object . freeze ( { ignore : Object . freeze ( [ ] ) } ) ) ;
88
+ globby . sync ( [ '*.tmp' , '!b.tmp' ] , Object . freeze ( { ignore : Object . freeze ( [ ] ) } ) ) ;
83
89
t . pass ( ) ;
84
90
} ) ;
85
91
86
92
test ( 'expose generateGlobTasks' , t => {
87
- const tasks = m . generateGlobTasks ( [ '*.tmp' , '!b.tmp' ] , { ignore : [ 'c.tmp' ] } ) ;
93
+ const tasks = globby . generateGlobTasks ( [ '*.tmp' , '!b.tmp' ] , { ignore : [ 'c.tmp' ] } ) ;
88
94
89
95
t . is ( tasks . length , 1 ) ;
90
96
t . is ( tasks [ 0 ] . pattern , '*.tmp' ) ;
91
97
t . deepEqual ( tasks [ 0 ] . options . ignore , [ 'c.tmp' , 'b.tmp' ] ) ;
92
98
} ) ;
93
99
94
100
test ( 'expose hasMagic' , t => {
95
- t . true ( m . hasMagic ( '**' ) ) ;
96
- t . true ( m . hasMagic ( [ '**' , 'path1' , 'path2' ] ) ) ;
97
- t . false ( m . hasMagic ( [ 'path1' , 'path2' ] ) ) ;
101
+ t . true ( globby . hasMagic ( '**' ) ) ;
102
+ t . true ( globby . hasMagic ( [ '**' , 'path1' , 'path2' ] ) ) ;
103
+ t . false ( globby . hasMagic ( [ 'path1' , 'path2' ] ) ) ;
98
104
} ) ;
99
105
100
106
test ( 'expandDirectories option' , t => {
101
- t . deepEqual ( m . sync ( tmp ) , [ 'tmp/a.tmp' , 'tmp/b.tmp' , 'tmp/c.tmp' , 'tmp/d.tmp' , 'tmp/e.tmp' ] ) ;
102
- t . deepEqual ( m . sync ( '**' , { cwd : tmp } ) , [ 'a.tmp' , 'b.tmp' , 'c.tmp' , 'd.tmp' , 'e.tmp' ] ) ;
103
- t . deepEqual ( m . sync ( tmp , { expandDirectories : [ 'a*' , 'b*' ] } ) , [ 'tmp/a.tmp' , 'tmp/b.tmp' ] ) ;
104
- t . deepEqual ( m . sync ( tmp , {
107
+ t . deepEqual ( globby . sync ( tmp ) , [ 'tmp/a.tmp' , 'tmp/b.tmp' , 'tmp/c.tmp' , 'tmp/d.tmp' , 'tmp/e.tmp' ] ) ;
108
+ t . deepEqual ( globby . sync ( '**' , { cwd : tmp } ) , [ 'a.tmp' , 'b.tmp' , 'c.tmp' , 'd.tmp' , 'e.tmp' ] ) ;
109
+ t . deepEqual ( globby . sync ( tmp , { expandDirectories : [ 'a*' , 'b*' ] } ) , [ 'tmp/a.tmp' , 'tmp/b.tmp' ] ) ;
110
+ t . deepEqual ( globby . sync ( tmp , {
105
111
expandDirectories : {
106
112
files : [ 'a' , 'b' ] ,
107
113
extensions : [ 'tmp' ]
108
114
}
109
115
} ) , [ 'tmp/a.tmp' , 'tmp/b.tmp' ] ) ;
110
- t . deepEqual ( m . sync ( tmp , {
116
+ t . deepEqual ( globby . sync ( tmp , {
111
117
expandDirectories : {
112
118
files : [ 'a' , 'b' ] ,
113
119
extensions : [ 'tmp' ]
@@ -117,30 +123,30 @@ test('expandDirectories option', t => {
117
123
} ) ;
118
124
119
125
test ( 'expandDirectories:true and onlyFiles:true option' , t => {
120
- t . deepEqual ( m . sync ( tmp , { onlyFiles : true } ) , [ 'tmp/a.tmp' , 'tmp/b.tmp' , 'tmp/c.tmp' , 'tmp/d.tmp' , 'tmp/e.tmp' ] ) ;
126
+ t . deepEqual ( globby . sync ( tmp , { onlyFiles : true } ) , [ 'tmp/a.tmp' , 'tmp/b.tmp' , 'tmp/c.tmp' , 'tmp/d.tmp' , 'tmp/e.tmp' ] ) ;
121
127
} ) ;
122
128
123
129
test . failing ( 'expandDirectories:true and onlyFiles:false option' , t => {
124
130
// Node-glob('tmp/**') => ['tmp', 'tmp/a.tmp', 'tmp/b.tmp', 'tmp/c.tmp', 'tmp/d.tmp', 'tmp/e.tmp']
125
131
// Fast-glob('tmp/**') => ['tmp/a.tmp', 'tmp/b.tmp', 'tmp/c.tmp', 'tmp/d.tmp', 'tmp/e.tmp']
126
132
// See https://github.com/mrmlnc/fast-glob/issues/47
127
- t . deepEqual ( m . sync ( tmp , { onlyFiles : false } ) , [ 'tmp' , 'tmp/a.tmp' , 'tmp/b.tmp' , 'tmp/c.tmp' , 'tmp/d.tmp' , 'tmp/e.tmp' ] ) ;
133
+ t . deepEqual ( globby . sync ( tmp , { onlyFiles : false } ) , [ 'tmp' , 'tmp/a.tmp' , 'tmp/b.tmp' , 'tmp/c.tmp' , 'tmp/d.tmp' , 'tmp/e.tmp' ] ) ;
128
134
} ) ;
129
135
130
136
test ( 'expandDirectories and ignores option' , t => {
131
- t . deepEqual ( m . sync ( 'tmp' , {
137
+ t . deepEqual ( globby . sync ( 'tmp' , {
132
138
ignore : [ 'tmp' ]
133
139
} ) , [ ] ) ;
134
140
135
- t . deepEqual ( m . sync ( 'tmp/**' , {
141
+ t . deepEqual ( globby . sync ( 'tmp/**' , {
136
142
expandDirectories : false ,
137
143
ignore : [ 'tmp' ]
138
144
} ) , [ 'tmp/a.tmp' , 'tmp/b.tmp' , 'tmp/c.tmp' , 'tmp/d.tmp' , 'tmp/e.tmp' ] ) ;
139
145
} ) ;
140
146
141
147
test . failing ( 'relative paths and ignores option' , t => {
142
148
process . chdir ( tmp ) ;
143
- t . deepEqual ( m . sync ( '../tmp' , {
149
+ t . deepEqual ( globby . sync ( '../tmp' , {
144
150
cwd : process . cwd ( ) ,
145
151
ignore : [ 'tmp' ]
146
152
} ) , [ ] ) ;
@@ -170,55 +176,55 @@ test.failing('relative paths and ignores option', t => {
170
176
const msg = 'Patterns must be a string or an array of strings' ;
171
177
172
178
test ( `rejects the promise for invalid patterns input: ${ valstring } - async` , async t => {
173
- await t . throwsAsync ( m ( v ) , TypeError ) ;
174
- await t . throwsAsync ( m ( v ) , msg ) ;
179
+ await t . throwsAsync ( globby ( v ) , TypeError ) ;
180
+ await t . throwsAsync ( globby ( v ) , msg ) ;
175
181
} ) ;
176
182
177
183
test ( `throws for invalid patterns input: ${ valstring } ` , t => {
178
- t . throws ( ( ) => m . sync ( v ) , TypeError ) ;
179
- t . throws ( ( ) => m . sync ( v ) , msg ) ;
184
+ t . throws ( ( ) => globby . sync ( v ) , TypeError ) ;
185
+ t . throws ( ( ) => globby . sync ( v ) , msg ) ;
180
186
} ) ;
181
187
182
188
test ( `generateGlobTasks throws for invalid patterns input: ${ valstring } ` , t => {
183
- t . throws ( ( ) => m . generateGlobTasks ( v ) , TypeError ) ;
184
- t . throws ( ( ) => m . generateGlobTasks ( v ) , msg ) ;
189
+ t . throws ( ( ) => globby . generateGlobTasks ( v ) , TypeError ) ;
190
+ t . throws ( ( ) => globby . generateGlobTasks ( v ) , msg ) ;
185
191
} ) ;
186
192
} ) ;
187
193
188
194
test ( 'gitignore option defaults to false' , async t => {
189
- const actual = await m ( '*' , { onlyFiles : false } ) ;
195
+ const actual = await globby ( '*' , { onlyFiles : false } ) ;
190
196
t . true ( actual . indexOf ( 'node_modules' ) > - 1 ) ;
191
197
} ) ;
192
198
193
199
test ( 'gitignore option defaults to false - sync' , t => {
194
- const actual = m . sync ( '*' , { onlyFiles : false } ) ;
200
+ const actual = globby . sync ( '*' , { onlyFiles : false } ) ;
195
201
t . true ( actual . indexOf ( 'node_modules' ) > - 1 ) ;
196
202
} ) ;
197
203
198
204
test ( 'respects gitignore option true' , async t => {
199
- const actual = await m ( '*' , { gitignore : true , onlyFiles : false } ) ;
205
+ const actual = await globby ( '*' , { gitignore : true , onlyFiles : false } ) ;
200
206
t . false ( actual . indexOf ( 'node_modules' ) > - 1 ) ;
201
207
} ) ;
202
208
203
209
test ( 'respects gitignore option true - sync' , t => {
204
- const actual = m . sync ( '*' , { gitignore : true , onlyFiles : false } ) ;
210
+ const actual = globby . sync ( '*' , { gitignore : true , onlyFiles : false } ) ;
205
211
t . false ( actual . indexOf ( 'node_modules' ) > - 1 ) ;
206
212
} ) ;
207
213
208
214
test ( 'respects gitignore option false' , async t => {
209
- const actual = await m ( '*' , { gitignore : false , onlyFiles : false } ) ;
215
+ const actual = await globby ( '*' , { gitignore : false , onlyFiles : false } ) ;
210
216
t . true ( actual . indexOf ( 'node_modules' ) > - 1 ) ;
211
217
} ) ;
212
218
213
219
test ( 'respects gitignore option false - sync' , t => {
214
- const actual = m . sync ( '*' , { gitignore : false , onlyFiles : false } ) ;
220
+ const actual = globby . sync ( '*' , { gitignore : false , onlyFiles : false } ) ;
215
221
t . true ( actual . indexOf ( 'node_modules' ) > - 1 ) ;
216
222
} ) ;
217
223
218
224
// https://github.com/sindresorhus/globby/issues/97
219
225
test . failing ( '`{extension: false}` and `expandDirectories.extensions` option' , t => {
220
226
t . deepEqual (
221
- m . sync ( tmp , {
227
+ globby . sync ( tmp , {
222
228
extension : false ,
223
229
expandDirectories : {
224
230
extensions : [
@@ -240,17 +246,17 @@ test.failing('`{extension: false}` and `expandDirectories.extensions` option', t
240
246
// https://github.com/sindresorhus/globby/issues/105
241
247
test . failing ( 'throws ENOTDIR when specifying a file as cwd - async' , async t => {
242
248
const isFile = path . resolve ( 'fixtures/gitignore/bar.js' ) ;
243
- await t . throwsAsync ( m ( '.' , { cwd : isFile } ) , { code : 'ENOTDIR' } ) ;
244
- await t . throwsAsync ( m ( '*' , { cwd : isFile } ) , { code : 'ENOTDIR' } ) ;
249
+ await t . throwsAsync ( globby ( '.' , { cwd : isFile } ) , { code : 'ENOTDIR' } ) ;
250
+ await t . throwsAsync ( globby ( '*' , { cwd : isFile } ) , { code : 'ENOTDIR' } ) ;
245
251
} ) ;
246
252
247
253
// https://github.com/sindresorhus/globby/issues/105
248
254
test . failing ( 'throws ENOTDIR when specifying a file as cwd - sync' , t => {
249
255
const isFile = path . resolve ( 'fixtures/gitignore/bar.js' ) ;
250
256
t . throws ( ( ) => {
251
- m . sync ( '.' , { cwd : isFile } ) ;
257
+ globby . sync ( '.' , { cwd : isFile } ) ;
252
258
} , { code : 'ENOTDIR' } ) ;
253
259
t . throws ( ( ) => {
254
- m . sync ( '*' , { cwd : isFile } ) ;
260
+ globby . sync ( '*' , { cwd : isFile } ) ;
255
261
} , { code : 'ENOTDIR' } ) ;
256
262
} ) ;
0 commit comments