| | 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.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) |
| | }) |
| |
|
| | test('option: ignorePatterns', async () => { |
| | const ignorePatterns: RegExp[] = [] |
| |
|
| | |
| | expect('README' in dataDirectory(fixturesDir)).toBe(false) |
| |
|
| | |
| | expect('README' in dataDirectory(fixturesDir, { ignorePatterns })).toBe(true) |
| | }) |
| | }) |
| |
|