Skip to content

Commit

Permalink
even more comprehensive tests for #515
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Mar 22, 2023
1 parent 672c944 commit 2054644
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions test/memfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,36 @@ if (process.platform === 'win32') {
t.plan(0, 'this test does not work on windows')
process.exit(0)
}

import { fs as memfs, vol } from 'memfs'
import t from 'tap'
import { glob } from '../'
t.beforeEach(() => vol.fromJSON({ '/x': 'abc' }))

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

t.test('should match single file with pattern', async t => {
const expandedFiles = await glob(['.', '/**/*'], { nodir: true, fs })
t.strictSame(expandedFiles, ['/x'])
})
const mock = {
fs: memfs,
'fs/promises': memfs.promises,
}

t.test('should match single file without pattern', async t => {
const expandedFiles = await glob(['.', '/x'], { nodir: true, fs })
t.strictSame(expandedFiles, ['/x'])
})
const patterns = ['/**/*', '/*', '/x']
const cwds = ['/', undefined]
for (const pattern of patterns) {
t.test(pattern, async t => {
for (const cwd of cwds) {
t.test(`cwd=${cwd}`, async t => {
t.test('mocking the fs', async t => {
const { glob } = t.mock('../', {
...mock,
'path-scurry': t.mock('path-scurry', mock),
})
t.strictSame(await glob(pattern, { nodir: true, cwd }), ['/x'])
})
t.test('passing in fs argument', async t => {
t.strictSame(await glob(pattern, { nodir: true, cwd, fs }), ['/x'])
})
})
}
})
}

0 comments on commit 2054644

Please sign in to comment.