-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathindex.ts
More file actions
46 lines (37 loc) · 1.47 KB
/
index.ts
File metadata and controls
46 lines (37 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { fileURLToPath } from 'url'
import path from 'path'
import { describe, expect, test } from 'vitest'
import dataDirectory from '@/data-directory/lib/data-directory'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const fixturesDir = path.join(__dirname, 'fixtures')
describe('data-directory', () => {
test('works', async () => {
const data = dataDirectory(fixturesDir)
const expected = {
bar: { another_markup_language: 'yes' },
foo: { meaningOfLife: 42 },
nested: { baz: 'I am markdown!' },
}
expect(data).toEqual(expected)
})
test('option: preprocess function', async () => {
function preprocess(content: string) {
return content.replace('markdown', 'MARKDOWN')
}
const data = dataDirectory(fixturesDir, { preprocess })
expect((data.nested as Record<string, unknown>).baz).toBe('I am MARKDOWN!')
})
test('option: extensions array', async () => {
const extensions = ['.yml', 'markdown']
const data = dataDirectory(fixturesDir, { extensions })
expect('bar' in data).toBe(true)
expect('foo' in data).toBe(false) // JSON file should be ignored
})
test('option: ignorePatterns', async () => {
const ignorePatterns: RegExp[] = []
// README is ignored by default
expect('README' in dataDirectory(fixturesDir)).toBe(false)
// README can be included by setting empty ignorePatterns array
expect('README' in dataDirectory(fixturesDir, { ignorePatterns })).toBe(true)
})
})