-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathplugin.test.mjs
More file actions
67 lines (58 loc) · 1.77 KB
/
plugin.test.mjs
File metadata and controls
67 lines (58 loc) · 1.77 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import assert from 'node:assert/strict';
import { describe, it, mock } from 'node:test';
// Simplified mocks - only mock what's actually needed
mock.module('../index.mjs', {
defaultExport: () => ({ highlightToHast: mock.fn(() => ({ children: [] })) }),
});
mock.module('classnames', {
defaultExport: (...args) => args.filter(Boolean).join(' '),
});
mock.module('hast-util-to-string', {
namedExports: { toString: () => 'code' },
});
const mockVisit = mock.fn();
mock.module('unist-util-visit', {
namedExports: { visit: mockVisit, SKIP: Symbol() },
});
describe('rehypeShikiji', async () => {
const { default: rehypeShikiji } = await import('../plugin.mjs');
const mockTree = { type: 'root', children: [] };
it('calls visit twice', async () => {
mockVisit.mock.resetCalls();
await rehypeShikiji()(mockTree);
assert.strictEqual(mockVisit.mock.calls.length, 2);
});
it('creates CodeTabs for multiple code blocks', async () => {
const parent = {
children: [
{
tagName: 'pre',
children: [
{
tagName: 'code',
data: { meta: 'displayName="JS"' },
properties: { className: ['language-js'] },
},
],
},
{
tagName: 'pre',
children: [
{
tagName: 'code',
data: { meta: 'displayName="TS"' },
properties: { className: ['language-ts'] },
},
],
},
],
};
mockVisit.mock.mockImplementation((tree, selector, visitor) => {
if (selector === 'element') {
visitor(parent.children[0], 0, parent);
}
});
await rehypeShikiji()(mockTree);
assert.ok(parent.children.some(child => child.tagName === 'CodeTabs'));
});
});