MCPcopy Create free account
hub / github.com/nodejs/nodejs.org / testRule

Function testRule

packages/remark-lint/src/rules/__tests__/utils.mjs:10–35  ·  view source on GitHub ↗
(
  rule,
  markdown,
  expected,
  vfileOptions = {},
  ruleOptions = {}
)

Source from the content-addressed store, hash-verified

8 * Tests a markdown rule against a markdown string
9 */
10export 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

Calls 1

ruleFunction · 0.85

Tested by

no test coverage detected