@@ -2,19 +2,36 @@ if (process.platform === 'win32') {
2
2
t . plan ( 0 , 'this test does not work on windows' )
3
3
process . exit ( 0 )
4
4
}
5
+
5
6
import { fs as memfs , vol } from 'memfs'
6
7
import t from 'tap'
7
8
import { glob } from '../'
8
9
t . beforeEach ( ( ) => vol . fromJSON ( { '/x' : 'abc' } ) )
9
10
10
11
const fs = memfs as unknown as typeof import ( 'fs' )
11
12
12
- t . test ( 'should match single file with pattern' , async t => {
13
- const expandedFiles = await glob ( [ '.' , '/**/*' ] , { nodir : true , fs } )
14
- t . strictSame ( expandedFiles , [ '/x' ] )
15
- } )
13
+ const mock = {
14
+ fs : memfs ,
15
+ 'fs/promises' : memfs . promises ,
16
+ }
16
17
17
- t . test ( 'should match single file without pattern' , async t => {
18
- const expandedFiles = await glob ( [ '.' , '/x' ] , { nodir : true , fs } )
19
- t . strictSame ( expandedFiles , [ '/x' ] )
20
- } )
18
+ const patterns = [ '/**/*' , '/*' , '/x' ]
19
+ const cwds = [ '/' , undefined ]
20
+ for ( const pattern of patterns ) {
21
+ t . test ( pattern , async t => {
22
+ for ( const cwd of cwds ) {
23
+ t . test ( `cwd=${ cwd } ` , async t => {
24
+ t . test ( 'mocking the fs' , async t => {
25
+ const { glob } = t . mock ( '../' , {
26
+ ...mock ,
27
+ 'path-scurry' : t . mock ( 'path-scurry' , mock ) ,
28
+ } )
29
+ t . strictSame ( await glob ( pattern , { nodir : true , cwd } ) , [ '/x' ] )
30
+ } )
31
+ t . test ( 'passing in fs argument' , async t => {
32
+ t . strictSame ( await glob ( pattern , { nodir : true , cwd, fs } ) , [ '/x' ] )
33
+ } )
34
+ } )
35
+ }
36
+ } )
37
+ }
0 commit comments