File tree Expand file tree Collapse file tree 2 files changed +26
-15
lines changed
testing/test-setup/src/lib/extend Expand file tree Collapse file tree 2 files changed +26
-15
lines changed Original file line number Diff line number Diff line change @@ -19,11 +19,10 @@ function assertMarkdownTableRow(
1919 . filter ( line => line . startsWith ( '|' ) && line . endsWith ( '|' ) )
2020 . map ( line =>
2121 line
22- . split ( '|' )
23- . map ( cell => cell . trim ( ) )
22+ . split ( / (?< ! \\ ) \| / )
23+ . map ( cell => cell . replace ( / \\ \| / g , '|' ) . trim ( ) )
2424 . filter ( Boolean ) ,
25- )
26- . filter ( row => row . some ( cell => / \w / . test ( cell ) ) ) ;
25+ ) ;
2726
2827 const pass = rows . some (
2928 row =>
Original file line number Diff line number Diff line change 11import { describe , expect , it } from 'vitest' ;
22
33describe ( 'markdown-table-matcher' , ( ) => {
4- const markdown = `
5- | 🏷 Category | ⭐ Score | 🛡 Audits |
6- |--------------|-------------|-----------|
7- | Performance | 🟡 **61** | 2 |
8- | SEO | 🟢 **100** | 1 |
9- | PWA | 🔴 **0** | 1 |
10- ` ;
4+ it ( 'should match table rows' , ( ) => {
5+ const markdown = `
6+ | 🏷 Category | ⭐ Score | 🛡 Audits |
7+ | :-------------------------- | :-------: | :-------: |
8+ | [Security](#security) | 🟡 **81** | 2 |
9+ | [Performance](#performance) | 🟡 **64** | 56 |
10+ | [SEO](#seo) | 🟡 **61** | 11 |
11+ ` ;
1112
12- it ( 'toContainMarkdownTableRow matches correctly' , ( ) => {
1313 expect ( markdown ) . toContainMarkdownTableRow ( [
1414 '🏷 Category' ,
1515 '⭐ Score' ,
1616 '🛡 Audits' ,
1717 ] ) ;
1818 expect ( markdown ) . toContainMarkdownTableRow ( [
19- 'Performance' ,
20- '🟡 **61 **' ,
21- '2 ' ,
19+ '[ Performance](#performance) ' ,
20+ '🟡 **64 **' ,
21+ '56 ' ,
2222 ] ) ;
2323 expect ( markdown ) . not . toContainMarkdownTableRow ( [
2424 'Non-existent cell' ,
2525 'Row cell' ,
2626 'Test cell' ,
2727 ] ) ;
2828 } ) ;
29+
30+ it ( 'should match table row with escaped pipe symbols' , ( ) => {
31+ const markdown = `
32+ | Package | Versions |
33+ | :--------- | :----------------------- |
34+ | \`eslint\` | \`^8.0.0 \\|\\| ^9.0.0\` |
35+ ` ;
36+ expect ( markdown ) . toContainMarkdownTableRow ( [
37+ '`eslint`' ,
38+ '`^8.0.0 || ^9.0.0`' ,
39+ ] ) ;
40+ } ) ;
2941} ) ;
You can’t perform that action at this time.
0 commit comments