From 791597de6ad7a0280848223cb17be7a561ad6c95 Mon Sep 17 00:00:00 2001 From: luojiyin Date: Wed, 1 Jul 2026 23:14:41 +0800 Subject: [PATCH 1/3] test(gfm): add remark-gfm plugin test coverage --- __tests__/plugins/gfm.spec.ts | 66 +++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 __tests__/plugins/gfm.spec.ts diff --git a/__tests__/plugins/gfm.spec.ts b/__tests__/plugins/gfm.spec.ts new file mode 100644 index 0000000..42a4895 --- /dev/null +++ b/__tests__/plugins/gfm.spec.ts @@ -0,0 +1,66 @@ +const { parseMd } = require('../../dist/lint-md-parser.cjs'); + +describe('remark-gfm plugin', () => { + test('table', () => { + const root = parseMd('| a | b |\n|---|---|\n| 1 | 2 |'); + expect(root.children).toHaveLength(1); + const node = root.children[0]; + expect(node.type).toBe('table'); + if (node.type === 'table') { + expect(node.align).toEqual([null, null]); + expect(node.children).toHaveLength(2); + } + }); + + test('task list with checked and unchecked items', () => { + const root = parseMd('- [x] done\n- [ ] todo'); + expect(root.children).toHaveLength(1); + const list = root.children[0]; + expect(list.type).toBe('list'); + if (list.type === 'list') { + expect(list.children).toHaveLength(2); + expect(list.children[0].type).toBe('listItem'); + expect(list.children[0].checked).toBe(true); + expect(list.children[1].type).toBe('listItem'); + expect(list.children[1].checked).toBe(false); + } + }); + + test('footnote definition', () => { + const root = parseMd('[^1]: note'); + expect(root.children).toHaveLength(1); + const node = root.children[0]; + expect(node.type).toBe('footnoteDefinition'); + if (node.type === 'footnoteDefinition') { + expect(node.identifier).toBe('1'); + } + }); + + test('autolink email', () => { + const root = parseMd(''); + const paragraph = root.children[0]; + expect(paragraph.type).toBe('paragraph'); + if (paragraph.type === 'paragraph') { + expect(paragraph.children).toHaveLength(1); + const link = paragraph.children[0]; + expect(link.type).toBe('link'); + if (link.type === 'link') { + expect(link.url).toBe('mailto:contact@example.com'); + } + } + }); + + test('bare URL in line', () => { + const root = parseMd('visit https://example.com'); + const paragraph = root.children[0]; + expect(paragraph.type).toBe('paragraph'); + if (paragraph.type === 'paragraph') { + expect(paragraph.children).toHaveLength(2); + const link = paragraph.children[1]; + expect(link.type).toBe('link'); + if (link.type === 'link') { + expect(link.url).toBe('https://example.com'); + } + } + }); +}); From 0a81ef2d9e42321aad455d2813db5750644278cb Mon Sep 17 00:00:00 2001 From: luojiyin Date: Wed, 1 Jul 2026 23:19:31 +0800 Subject: [PATCH 2/3] test: extract parseMd to shared helpers to fix TS2451 redeclaration error --- __tests__/helpers.ts | 2 ++ __tests__/index.spec.ts | 3 +-- __tests__/plugins/directive.spec.ts | 2 +- __tests__/plugins/gfm.spec.ts | 2 +- __tests__/plugins/math.spec.ts | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 __tests__/helpers.ts diff --git a/__tests__/helpers.ts b/__tests__/helpers.ts new file mode 100644 index 0000000..ed5a50d --- /dev/null +++ b/__tests__/helpers.ts @@ -0,0 +1,2 @@ +const parser = require('../dist/lint-md-parser.cjs'); +export const { parseMd, revertMdAstNode, stringifyMdAst } = parser; diff --git a/__tests__/index.spec.ts b/__tests__/index.spec.ts index ebd0b8d..6b994a2 100644 --- a/__tests__/index.spec.ts +++ b/__tests__/index.spec.ts @@ -1,8 +1,7 @@ import * as fs from 'fs'; import * as path from 'path'; import { execFileSync } from 'child_process'; - -const { parseMd, revertMdAstNode, stringifyMdAst } = require('../dist/lint-md-parser.cjs'); +import { parseMd, revertMdAstNode, stringifyMdAst } from './helpers'; describe('test lint-md-parser', () => { const mdDemo = fs diff --git a/__tests__/plugins/directive.spec.ts b/__tests__/plugins/directive.spec.ts index 7fb00af..9f33eda 100644 --- a/__tests__/plugins/directive.spec.ts +++ b/__tests__/plugins/directive.spec.ts @@ -1,4 +1,4 @@ -const { parseMd } = require('../../dist/lint-md-parser.cjs'); +import { parseMd } from '../helpers'; describe('remark-directive plugin', () => { test('container directive :::note', () => { diff --git a/__tests__/plugins/gfm.spec.ts b/__tests__/plugins/gfm.spec.ts index 42a4895..fe15b75 100644 --- a/__tests__/plugins/gfm.spec.ts +++ b/__tests__/plugins/gfm.spec.ts @@ -1,4 +1,4 @@ -const { parseMd } = require('../../dist/lint-md-parser.cjs'); +import { parseMd } from '../helpers'; describe('remark-gfm plugin', () => { test('table', () => { diff --git a/__tests__/plugins/math.spec.ts b/__tests__/plugins/math.spec.ts index fa2d32b..a0266e5 100644 --- a/__tests__/plugins/math.spec.ts +++ b/__tests__/plugins/math.spec.ts @@ -1,4 +1,4 @@ -const { parseMd } = require('../../dist/lint-md-parser.cjs'); +import { parseMd } from '../helpers'; describe('remark-math plugin', () => { test('block math with $$ on separate lines', () => { From e0427f473cc37fa9021f253fcaa2477e15227948 Mon Sep 17 00:00:00 2001 From: luojiyin Date: Wed, 1 Jul 2026 23:24:12 +0800 Subject: [PATCH 3/3] test(gfm): add footnote reference and table alignment tests --- __tests__/plugins/gfm.spec.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/__tests__/plugins/gfm.spec.ts b/__tests__/plugins/gfm.spec.ts index fe15b75..1916c7f 100644 --- a/__tests__/plugins/gfm.spec.ts +++ b/__tests__/plugins/gfm.spec.ts @@ -1,13 +1,13 @@ import { parseMd } from '../helpers'; describe('remark-gfm plugin', () => { - test('table', () => { - const root = parseMd('| a | b |\n|---|---|\n| 1 | 2 |'); + test('table with alignment', () => { + const root = parseMd('| a | b |\n|:---|---:|\n| 1 | 2 |'); expect(root.children).toHaveLength(1); const node = root.children[0]; expect(node.type).toBe('table'); if (node.type === 'table') { - expect(node.align).toEqual([null, null]); + expect(node.align).toEqual(['left', 'right']); expect(node.children).toHaveLength(2); } }); @@ -36,6 +36,19 @@ describe('remark-gfm plugin', () => { } }); + test('footnote reference', () => { + const root = parseMd('text [^1]\n\n[^1]: note'); + const paragraph = root.children[0]; + expect(paragraph.type).toBe('paragraph'); + if (paragraph.type === 'paragraph') { + const ref = paragraph.children.find((child) => child.type === 'footnoteReference'); + expect(ref).toBeDefined(); + if (ref?.type === 'footnoteReference') { + expect(ref.identifier).toBe('1'); + } + } + }); + test('autolink email', () => { const root = parseMd(''); const paragraph = root.children[0];