Skip to content

Commit fbfaf2d

Browse files
committed
test: enhance matcher to support empty cells
1 parent 38a80d7 commit fbfaf2d

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

testing/test-setup/src/lib/extend/markdown-table.matcher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ function assertMarkdownTableRow(
1919
.filter(line => line.startsWith('|') && line.endsWith('|'))
2020
.map(line =>
2121
line
22+
.slice(1, -1)
2223
.split(/(?<!\\)\|/)
23-
.map(cell => cell.replace(/\\\|/g, '|').trim())
24-
.filter(Boolean),
24+
.map(cell => cell.replace(/\\\|/g, '|').trim()),
2525
);
2626

2727
const pass = rows.some(

testing/test-setup/src/lib/extend/markdown-table.matcher.unit.test.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, it } from 'vitest';
22

33
describe('markdown-table-matcher', () => {
4-
it('should match table rows', () => {
4+
it('should match header and data rows in a markdown table', () => {
55
const markdown = `
66
| 🏷 Category | ⭐ Score | 🛡 Audits |
77
| :-------------------------- | :-------: | :-------: |
@@ -15,6 +15,11 @@ describe('markdown-table-matcher', () => {
1515
'⭐ Score',
1616
'🛡 Audits',
1717
]);
18+
expect(markdown).toContainMarkdownTableRow([
19+
':--------------------------',
20+
':-------:',
21+
':-------:',
22+
]);
1823
expect(markdown).toContainMarkdownTableRow([
1924
'[Performance](#performance)',
2025
'🟡 **64**',
@@ -27,7 +32,7 @@ describe('markdown-table-matcher', () => {
2732
]);
2833
});
2934

30-
it('should match table row with escaped pipe symbols', () => {
35+
it('should match table rows containing escaped pipe symbols', () => {
3136
const markdown = `
3237
| Package | Versions |
3338
| :--------- | :----------------------- |
@@ -38,4 +43,18 @@ describe('markdown-table-matcher', () => {
3843
'`^8.0.0 || ^9.0.0`',
3944
]);
4045
});
46+
47+
it('should match table rows with an empty cell', () => {
48+
const markdown = `
49+
| Severity | Message | Source file | Line(s) |
50+
| :--------: | :------------------------ | :-------------------- | :-----: |
51+
| 🚨 _error_ | File size is 20KB too big | \`list.component.ts\` | |
52+
`;
53+
expect(markdown).toContainMarkdownTableRow([
54+
'🚨 _error_',
55+
'File size is 20KB too big',
56+
'`list.component.ts`',
57+
'',
58+
]);
59+
});
4160
});

0 commit comments

Comments
 (0)