2023-11-16 14:13:19 +00:00
|
|
|
import { describe, expect, test } from 'bun:test'
|
|
|
|
import { render } from './utils.ts'
|
|
|
|
|
|
|
|
describe('options', () => {
|
|
|
|
test('empty options', async () => {
|
|
|
|
expect(await render('simple.md', {})).toMatchSnapshot()
|
|
|
|
})
|
|
|
|
|
|
|
|
test('set root directory', async () => {
|
|
|
|
expect(await render('relative.md', { root: 'tests/fixtures' }))
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('matcher', () => {
|
|
|
|
test('custom matcher', async () => {
|
|
|
|
const matcher = /foo '(?<file>.+)'/g
|
|
|
|
expect(await render('matcher-a.md', { matcher })).toMatchSnapshot()
|
|
|
|
})
|
|
|
|
test('custom matcher', async () => {
|
|
|
|
const matcher = /\$(?<file>.+)\$/g
|
|
|
|
expect(await render('matcher-b.md', { matcher })).toMatchSnapshot()
|
|
|
|
})
|
|
|
|
|
|
|
|
test('fail for non global regexp', async () => {
|
|
|
|
const matcher = /foo '(?<file>.+)'/
|
|
|
|
expect(() => render('matcher-a.md', { matcher })).toThrow('RegExp must be global')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('fail for missing "file" group', async () => {
|
|
|
|
const matcher = /foo '(.+)'/g
|
|
|
|
expect(() => render('matcher-a.md', { matcher })).toThrow('Regexp must expose a named group "file"')
|
|
|
|
})
|
|
|
|
})
|
2023-11-16 14:43:48 +00:00
|
|
|
|
|
|
|
test('do not trim', async () => {
|
|
|
|
expect(await render('whole.md', { trim: false })).toMatchSnapshot()
|
|
|
|
})
|
2023-11-16 14:13:19 +00:00
|
|
|
})
|