|
|
|
|
@ -1,15 +1,18 @@
|
|
|
|
|
import type { MarkdownItAsync } from 'markdown-it-async'
|
|
|
|
|
import { mergeConfig } from 'node/config'
|
|
|
|
|
import { mergeConfig, type UserConfig } from 'node/config'
|
|
|
|
|
|
|
|
|
|
describe('node/config', () => {
|
|
|
|
|
test('merges markdown config hooks from extended configs', async () => {
|
|
|
|
|
test('merges markdown hooks from extended configs', async () => {
|
|
|
|
|
const calls: string[] = []
|
|
|
|
|
const md = {} as MarkdownItAsync
|
|
|
|
|
|
|
|
|
|
const merged = mergeConfig(
|
|
|
|
|
const merged = mergeConfig<UserConfig, UserConfig>(
|
|
|
|
|
{
|
|
|
|
|
markdown: {
|
|
|
|
|
lineNumbers: true,
|
|
|
|
|
preConfig() {
|
|
|
|
|
calls.push('base-pre')
|
|
|
|
|
},
|
|
|
|
|
config() {
|
|
|
|
|
calls.push('base')
|
|
|
|
|
}
|
|
|
|
|
@ -20,6 +23,9 @@ describe('node/config', () => {
|
|
|
|
|
attrs: {
|
|
|
|
|
allowedAttributes: ['id']
|
|
|
|
|
},
|
|
|
|
|
async preConfig() {
|
|
|
|
|
calls.push('extended-pre')
|
|
|
|
|
},
|
|
|
|
|
async config() {
|
|
|
|
|
calls.push('extended')
|
|
|
|
|
}
|
|
|
|
|
@ -32,8 +38,36 @@ describe('node/config', () => {
|
|
|
|
|
allowedAttributes: ['id']
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await merged.markdown?.preConfig?.(md)
|
|
|
|
|
await merged.markdown?.config?.(md)
|
|
|
|
|
|
|
|
|
|
expect(calls).toEqual(['base-pre', 'extended-pre', 'base', 'extended'])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('keeps one-sided markdown hooks when the other config omits them', async () => {
|
|
|
|
|
const calls: string[] = []
|
|
|
|
|
const md = {} as MarkdownItAsync
|
|
|
|
|
|
|
|
|
|
const merged = mergeConfig<UserConfig, UserConfig>(
|
|
|
|
|
{
|
|
|
|
|
markdown: {
|
|
|
|
|
preConfig() {
|
|
|
|
|
calls.push('base-pre')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
markdown: {
|
|
|
|
|
config() {
|
|
|
|
|
calls.push('extended')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
await merged.markdown?.preConfig?.(md)
|
|
|
|
|
await merged.markdown?.config?.(md)
|
|
|
|
|
|
|
|
|
|
expect(calls).toEqual(['base', 'extended'])
|
|
|
|
|
expect(calls).toEqual(['base-pre', 'extended'])
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|