From 8310caf3611641f43c33483cabb5879f6297520c Mon Sep 17 00:00:00 2001 From: Baptiste Leproux Date: Fri, 6 Mar 2026 10:43:48 +0100 Subject: [PATCH] test(spec): plugins as option --- packages/comark/SPEC/MDC/cjk.md | 6 ++++ .../MDC/emoji-inside-component-autounwrap.md | 2 ++ .../comark/SPEC/MDC/emoji-inside-component.md | 3 ++ packages/comark/SPEC/MDC/emoji.md | 3 ++ packages/comark/test/index.test.ts | 30 +++++++++++++++---- packages/comark/test/roundtrip.test.ts | 19 ------------ 6 files changed, 38 insertions(+), 25 deletions(-) delete mode 100644 packages/comark/test/roundtrip.test.ts diff --git a/packages/comark/SPEC/MDC/cjk.md b/packages/comark/SPEC/MDC/cjk.md index 081347b..5f53bbf 100644 --- a/packages/comark/SPEC/MDC/cjk.md +++ b/packages/comark/SPEC/MDC/cjk.md @@ -1,3 +1,9 @@ +--- +options: + plugins: + - cjk +--- + ## Input ```md diff --git a/packages/comark/SPEC/MDC/emoji-inside-component-autounwrap.md b/packages/comark/SPEC/MDC/emoji-inside-component-autounwrap.md index 1c29d07..dfaa4fc 100644 --- a/packages/comark/SPEC/MDC/emoji-inside-component-autounwrap.md +++ b/packages/comark/SPEC/MDC/emoji-inside-component-autounwrap.md @@ -5,6 +5,8 @@ timeout: markdown: 5ms options: autoUnwrap: true + plugins: + - emoji --- ## Input diff --git a/packages/comark/SPEC/MDC/emoji-inside-component.md b/packages/comark/SPEC/MDC/emoji-inside-component.md index f26ae2b..8c12c40 100644 --- a/packages/comark/SPEC/MDC/emoji-inside-component.md +++ b/packages/comark/SPEC/MDC/emoji-inside-component.md @@ -3,6 +3,9 @@ timeout: parse: 5ms html: 5ms markdown: 5ms +options: + plugins: + - emoji --- ## Input diff --git a/packages/comark/SPEC/MDC/emoji.md b/packages/comark/SPEC/MDC/emoji.md index 19ec9b3..4b4f8e1 100644 --- a/packages/comark/SPEC/MDC/emoji.md +++ b/packages/comark/SPEC/MDC/emoji.md @@ -3,6 +3,9 @@ timeout: parse: 5ms html: 5ms markdown: 5ms +options: + plugins: + - emoji --- ## Input diff --git a/packages/comark/test/index.test.ts b/packages/comark/test/index.test.ts index 568ee92..e195933 100644 --- a/packages/comark/test/index.test.ts +++ b/packages/comark/test/index.test.ts @@ -14,6 +14,14 @@ import minLight from '@shikijs/themes/min-light' import nord from '@shikijs/themes/nord' import rustLanguage from '@shikijs/langs/rust' import goLanguage from '@shikijs/langs/go' +import type { ParseOptions } from '../src/types' + +type PluginName = 'cjk' | 'emoji' + +const pluginRegistry: Record ComarkPlugin> = { + cjk, + emoji, +} interface TestCase { input: string @@ -27,6 +35,8 @@ interface TestCase { } options?: { highlight?: HighlightOptions + plugins?: PluginName[] + autoUnwrap?: boolean } } @@ -176,7 +186,9 @@ describe('Comark Tests', () => { let parsedAST: Awaited> beforeAll(async () => { - const plugins: ComarkPlugin[] = [cjk(), emoji()] + const declaredPlugins = testCase.options?.plugins ?? [] + const plugins: ComarkPlugin[] = declaredPlugins.map(name => pluginRegistry[name]()) + if (testCase.options?.highlight) { const themes = { 'min-light': minLight, @@ -193,11 +205,17 @@ describe('Comark Tests', () => { }, })) } - parsedAST = await parse(testCase.input, { - autoUnwrap: false, - ...testCase.options, - plugins, - }) + + const parseOptions: ParseOptions = { + autoUnwrap: testCase.options?.autoUnwrap ?? false, + ...testCase.options?.highlight ? { highlight: testCase.options.highlight } : {}, + } + + if (plugins.length > 0) { + parseOptions.plugins = plugins + } + + parsedAST = await parse(testCase.input, parseOptions) }, testCase.timeouts?.parse ?? 5000) it('should parse input to AST', () => { diff --git a/packages/comark/test/roundtrip.test.ts b/packages/comark/test/roundtrip.test.ts deleted file mode 100644 index bc58073..0000000 --- a/packages/comark/test/roundtrip.test.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { describe, it, expect } from 'vitest' -import { parse } from '../src/index' -import { renderMarkdown } from '../src/string' - -describe('MDC roundtrip', () => { - const roundtrip = async (input: string) => { - const ast = await parse(input) - return renderMarkdown(ast) - } - - describe('task list', () => { - it('preserves checked and unchecked items', async () => { - const input = `- [x] Todo done\n- [ ] Todo` - - const output = await roundtrip(input) - expect(output).toBe(input) - }) - }) -})