Skip to content

Commit 2054644

Browse files
committed
even more comprehensive tests for #515
1 parent 672c944 commit 2054644

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

test/memfs.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,36 @@ if (process.platform === 'win32') {
22
t.plan(0, 'this test does not work on windows')
33
process.exit(0)
44
}
5+
56
import { fs as memfs, vol } from 'memfs'
67
import t from 'tap'
78
import { glob } from '../'
89
t.beforeEach(() => vol.fromJSON({ '/x': 'abc' }))
910

1011
const fs = memfs as unknown as typeof import('fs')
1112

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+
}
1617

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

Comments
 (0)