mirror of https://github.com/vuejs/vitepress
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
|
|
import { tmpdir } from 'node:os'
|
|
import path from 'node:path'
|
|
|
|
import { glob } from 'node/utils/glob'
|
|
|
|
describe('node/utils/glob', () => {
|
|
let root: string
|
|
|
|
beforeEach(async () => {
|
|
root = await mkdtemp(path.join(tmpdir(), 'vitepress-glob-'))
|
|
for (const dir of ['drafts', 'dist', 'node_modules']) {
|
|
await mkdir(path.join(root, dir))
|
|
await writeFile(path.join(root, dir, 'post.md'), '# Post')
|
|
}
|
|
await writeFile(path.join(root, 'published.md'), '# Published')
|
|
})
|
|
|
|
afterEach(async () => {
|
|
await rm(root, { recursive: true, force: true })
|
|
})
|
|
|
|
test.each([{ ignore: 'drafts/**' }, { ignore: ['drafts/**'] }])(
|
|
'accepts an ignore pattern as $ignore',
|
|
async ({ ignore }) => {
|
|
expect(await glob(['**/*.md'], { cwd: root, ignore })).toEqual([
|
|
'published.md'
|
|
])
|
|
}
|
|
)
|
|
|
|
test('keeps the default exclusions without a custom ignore pattern', async () => {
|
|
expect(await glob(['**/*.md'], { cwd: root })).toEqual([
|
|
'drafts/post.md',
|
|
'published.md'
|
|
])
|
|
})
|
|
})
|