forked from nodejs/doc-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetadata.test.mjs
More file actions
96 lines (91 loc) · 2.69 KB
/
metadata.test.mjs
File metadata and controls
96 lines (91 loc) · 2.69 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { strictEqual, deepStrictEqual } from 'node:assert';
import { describe, it } from 'node:test';
import GitHubSlugger from 'github-slugger';
import { VFile } from 'vfile';
import createMetadata from '../metadata.mjs';
import { u } from 'unist-builder';
describe('createMetadata', () => {
it('should set the heading correctly', () => {
const slugger = new GitHubSlugger();
const metadata = createMetadata(slugger);
const heading = u('heading', {
type: 'heading',
data: {
text: 'Test Heading',
type: 'test',
name: 'test',
depth: 1,
},
});
metadata.setHeading(heading);
strictEqual(metadata.create(new VFile(), {}).heading.data, heading.data);
});
it('should set the stability correctly', () => {
const slugger = new GitHubSlugger();
const metadata = createMetadata(slugger);
const stability = {
type: 'root',
data: { index: 2, description: '' },
children: [],
};
metadata.addStability(stability);
const actual = metadata.create(new VFile(), {}).stability;
deepStrictEqual(actual, {
children: [stability],
type: 'root',
});
});
it('should create a metadata entry correctly', () => {
const slugger = new GitHubSlugger();
const metadata = createMetadata(slugger);
const apiDoc = new VFile({ path: 'test.md' });
const section = { type: 'root', children: [] };
const heading = {
type: 'heading',
data: {
text: 'Test Heading',
type: 'test',
name: 'test',
depth: 1,
},
};
const stability = {
type: 'root',
data: { index: 2, description: '' },
children: [],
};
const properties = { source_link: 'test.com' };
metadata.setHeading(heading);
metadata.addStability(stability);
metadata.updateProperties(properties);
const expected = {
added_in: undefined,
api: 'test',
api_doc_source: 'doc/api/test.md',
changes: [],
content: section,
deprecated_in: undefined,
heading,
n_api_version: undefined,
introduced_in: undefined,
llm_description: undefined,
removed_in: undefined,
slug: 'test-heading',
source_link: 'test.com',
stability: { type: 'root', children: [stability] },
tags: [],
updates: [],
yaml_position: {},
};
const actual = metadata.create(apiDoc, section);
deepStrictEqual(actual, expected);
});
it('should be serializable', () => {
const { create } = createMetadata(new GitHubSlugger());
const actual = create(new VFile({ path: 'test.md' }), {
type: 'root',
children: [],
});
deepStrictEqual(structuredClone(actual), actual);
});
});