@@ -2,7 +2,7 @@ import fs from 'fs';
22import util from 'util' ;
33import path from 'path' ;
44import test from 'ava' ;
5- import m from '.' ;
5+ import globby from '.' ;
66
77const cwd = process . cwd ( ) ;
88const tmp = 'tmp' ;
@@ -18,96 +18,102 @@ test.before(() => {
1818 if ( ! fs . existsSync ( tmp ) ) {
1919 fs . mkdirSync ( tmp ) ;
2020 }
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+ }
2326} ) ;
2427
2528test . 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+
2834 fs . rmdirSync ( tmp ) ;
2935} ) ;
3036
3137test ( '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' ] ) ;
3339} ) ;
3440
3541test ( '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' ] ) ;
3743} ) ;
3844
3945test ( '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' ] ) ;
4147} ) ;
4248
4349test ( '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' ] ) ;
4551} ) ;
4652
4753test ( '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' ] ) ;
4955} ) ;
5056
5157test ( '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' ] ) ;
5561} ) ;
5662
5763test ( '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' ] ) ;
5965} ) ;
6066
6167test ( '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' ] ) , [ ] ) ;
6369} ) ;
6470
6571test ( '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' ] ) , [ ] ) ;
6773} ) ;
6874
6975test ( 'cwd option' , t => {
7076 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' ] ) ;
7379 process . chdir ( cwd ) ;
7480} ) ;
7581
7682test ( '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 ( [ ] ) } ) ) ;
7884 t . pass ( ) ;
7985} ) ;
8086
8187test ( '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 ( [ ] ) } ) ) ;
8389 t . pass ( ) ;
8490} ) ;
8591
8692test ( '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' ] } ) ;
8894
8995 t . is ( tasks . length , 1 ) ;
9096 t . is ( tasks [ 0 ] . pattern , '*.tmp' ) ;
9197 t . deepEqual ( tasks [ 0 ] . options . ignore , [ 'c.tmp' , 'b.tmp' ] ) ;
9298} ) ;
9399
94100test ( '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' ] ) ) ;
98104} ) ;
99105
100106test ( '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 , {
105111 expandDirectories : {
106112 files : [ 'a' , 'b' ] ,
107113 extensions : [ 'tmp' ]
108114 }
109115 } ) , [ 'tmp/a.tmp' , 'tmp/b.tmp' ] ) ;
110- t . deepEqual ( m . sync ( tmp , {
116+ t . deepEqual ( globby . sync ( tmp , {
111117 expandDirectories : {
112118 files : [ 'a' , 'b' ] ,
113119 extensions : [ 'tmp' ]
@@ -117,30 +123,30 @@ test('expandDirectories option', t => {
117123} ) ;
118124
119125test ( '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' ] ) ;
121127} ) ;
122128
123129test . failing ( 'expandDirectories:true and onlyFiles:false option' , t => {
124130 // Node-glob('tmp/**') => ['tmp', 'tmp/a.tmp', 'tmp/b.tmp', 'tmp/c.tmp', 'tmp/d.tmp', 'tmp/e.tmp']
125131 // Fast-glob('tmp/**') => ['tmp/a.tmp', 'tmp/b.tmp', 'tmp/c.tmp', 'tmp/d.tmp', 'tmp/e.tmp']
126132 // 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' ] ) ;
128134} ) ;
129135
130136test ( 'expandDirectories and ignores option' , t => {
131- t . deepEqual ( m . sync ( 'tmp' , {
137+ t . deepEqual ( globby . sync ( 'tmp' , {
132138 ignore : [ 'tmp' ]
133139 } ) , [ ] ) ;
134140
135- t . deepEqual ( m . sync ( 'tmp/**' , {
141+ t . deepEqual ( globby . sync ( 'tmp/**' , {
136142 expandDirectories : false ,
137143 ignore : [ 'tmp' ]
138144 } ) , [ 'tmp/a.tmp' , 'tmp/b.tmp' , 'tmp/c.tmp' , 'tmp/d.tmp' , 'tmp/e.tmp' ] ) ;
139145} ) ;
140146
141147test . failing ( 'relative paths and ignores option' , t => {
142148 process . chdir ( tmp ) ;
143- t . deepEqual ( m . sync ( '../tmp' , {
149+ t . deepEqual ( globby . sync ( '../tmp' , {
144150 cwd : process . cwd ( ) ,
145151 ignore : [ 'tmp' ]
146152 } ) , [ ] ) ;
@@ -170,55 +176,55 @@ test.failing('relative paths and ignores option', t => {
170176 const msg = 'Patterns must be a string or an array of strings' ;
171177
172178 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 ) ;
175181 } ) ;
176182
177183 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 ) ;
180186 } ) ;
181187
182188 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 ) ;
185191 } ) ;
186192} ) ;
187193
188194test ( 'gitignore option defaults to false' , async t => {
189- const actual = await m ( '*' , { onlyFiles : false } ) ;
195+ const actual = await globby ( '*' , { onlyFiles : false } ) ;
190196 t . true ( actual . indexOf ( 'node_modules' ) > - 1 ) ;
191197} ) ;
192198
193199test ( 'gitignore option defaults to false - sync' , t => {
194- const actual = m . sync ( '*' , { onlyFiles : false } ) ;
200+ const actual = globby . sync ( '*' , { onlyFiles : false } ) ;
195201 t . true ( actual . indexOf ( 'node_modules' ) > - 1 ) ;
196202} ) ;
197203
198204test ( 'respects gitignore option true' , async t => {
199- const actual = await m ( '*' , { gitignore : true , onlyFiles : false } ) ;
205+ const actual = await globby ( '*' , { gitignore : true , onlyFiles : false } ) ;
200206 t . false ( actual . indexOf ( 'node_modules' ) > - 1 ) ;
201207} ) ;
202208
203209test ( 'respects gitignore option true - sync' , t => {
204- const actual = m . sync ( '*' , { gitignore : true , onlyFiles : false } ) ;
210+ const actual = globby . sync ( '*' , { gitignore : true , onlyFiles : false } ) ;
205211 t . false ( actual . indexOf ( 'node_modules' ) > - 1 ) ;
206212} ) ;
207213
208214test ( 'respects gitignore option false' , async t => {
209- const actual = await m ( '*' , { gitignore : false , onlyFiles : false } ) ;
215+ const actual = await globby ( '*' , { gitignore : false , onlyFiles : false } ) ;
210216 t . true ( actual . indexOf ( 'node_modules' ) > - 1 ) ;
211217} ) ;
212218
213219test ( 'respects gitignore option false - sync' , t => {
214- const actual = m . sync ( '*' , { gitignore : false , onlyFiles : false } ) ;
220+ const actual = globby . sync ( '*' , { gitignore : false , onlyFiles : false } ) ;
215221 t . true ( actual . indexOf ( 'node_modules' ) > - 1 ) ;
216222} ) ;
217223
218224// https://github.com/sindresorhus/globby/issues/97
219225test . failing ( '`{extension: false}` and `expandDirectories.extensions` option' , t => {
220226 t . deepEqual (
221- m . sync ( tmp , {
227+ globby . sync ( tmp , {
222228 extension : false ,
223229 expandDirectories : {
224230 extensions : [
@@ -240,17 +246,17 @@ test.failing('`{extension: false}` and `expandDirectories.extensions` option', t
240246// https://github.com/sindresorhus/globby/issues/105
241247test . failing ( 'throws ENOTDIR when specifying a file as cwd - async' , async t => {
242248 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' } ) ;
245251} ) ;
246252
247253// https://github.com/sindresorhus/globby/issues/105
248254test . failing ( 'throws ENOTDIR when specifying a file as cwd - sync' , t => {
249255 const isFile = path . resolve ( 'fixtures/gitignore/bar.js' ) ;
250256 t . throws ( ( ) => {
251- m . sync ( '.' , { cwd : isFile } ) ;
257+ globby . sync ( '.' , { cwd : isFile } ) ;
252258 } , { code : 'ENOTDIR' } ) ;
253259 t . throws ( ( ) => {
254- m . sync ( '*' , { cwd : isFile } ) ;
260+ globby . sync ( '*' , { cwd : isFile } ) ;
255261 } , { code : 'ENOTDIR' } ) ;
256262} ) ;
0 commit comments