(
rule,
markdown,
expected,
vfileOptions = {},
ruleOptions = {}
)
| 8 | * Tests a markdown rule against a markdown string |
| 9 | */ |
| 10 | export const testRule = ( |
| 11 | rule, |
| 12 | markdown, |
| 13 | expected, |
| 14 | vfileOptions = {}, |
| 15 | ruleOptions = {} |
| 16 | ) => { |
| 17 | // Parse the markdown once |
| 18 | const tree = unified().use(remarkParse).parse(markdown); |
| 19 | |
| 20 | // Create a mock vfile |
| 21 | const vfile = { |
| 22 | ...vfileOptions, |
| 23 | message: mock.fn(), |
| 24 | messages: [], |
| 25 | }; |
| 26 | |
| 27 | // Execute the rule |
| 28 | rule(ruleOptions)(tree, vfile, () => {}); |
| 29 | |
| 30 | // Assert that the expected messages were reported |
| 31 | assert.deepEqual( |
| 32 | vfile.message.mock.calls.map(call => call.arguments[0]), |
| 33 | expected |
| 34 | ); |
| 35 | }; |
| 36 | |
| 37 | /** |
| 38 | * Tests a YAML rule against a YAML string |
no test coverage detected