-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathutils.mjs
More file actions
52 lines (44 loc) · 1.09 KB
/
utils.mjs
File metadata and controls
52 lines (44 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import assert from 'node:assert/strict';
import { mock } from 'node:test';
import remarkParse from 'remark-parse';
import { unified } from 'unified';
/**
* Tests a markdown rule against a markdown string
*/
export const testRule = (
rule,
markdown,
expected,
vfileOptions = {},
ruleOptions = {}
) => {
// Parse the markdown once
const tree = unified().use(remarkParse).parse(markdown);
// Create a mock vfile
const vfile = {
...vfileOptions,
message: mock.fn(),
messages: [],
};
// Execute the rule
rule(ruleOptions)(tree, vfile, () => {});
// Assert that the expected messages were reported
assert.deepEqual(
vfile.message.mock.calls.map(call => call.arguments[0]),
expected
);
};
/**
* Tests a YAML rule against a YAML string
*/
export function testYamlRule(rule, input, options = {}, expected) {
// Create a mock reporter
const report = mock.fn();
// Execute the rule
rule(input, report, options);
// Assert that the expected messages were reported
assert.deepEqual(
report.mock.calls.flatMap(call => call.arguments),
expected
);
}