-
Notifications
You must be signed in to change notification settings - Fork 30.5k
/
Copy pathtest-doctool-json.mjs
227 lines (221 loc) Β· 6.01 KB
/
test-doctool-json.mjs
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import * as common from '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import assert from 'assert';
import fs from 'fs';
import * as json from '../../tools/doc/json.mjs';
import {
remarkParse,
unified,
} from '../../tools/doc/deps.mjs';
function toJSON(input, filename, cb) {
function nullCompiler() {
this.Compiler = (tree) => tree;
}
unified()
.use(remarkParse)
.use(json.jsonAPI, { filename })
.use(nullCompiler)
.process(input, cb);
}
// Outputs valid json with the expected fields when given simple markdown
// Test data is a list of objects with two properties.
// The file property is the file path.
// The json property is some json which will be generated by the doctool.
const testData = [
{
file: fixtures.path('sample_document.md'),
json: {
type: 'module',
source: 'foo',
modules: [{
textRaw: 'Sample Markdown',
name: 'sample_markdown',
modules: [{
textRaw: 'Seussian Rhymes',
name: 'seussian_rhymes',
desc: '<ol>\n<li>fish</li>\n<li>fish</li>\n</ol>\n' +
'<ul>\n<li>Red fish</li>\n<li>Blue fish</li>\n</ul>',
type: 'module',
displayName: 'Seussian Rhymes',
}],
type: 'module',
displayName: 'Sample Markdown',
}],
},
},
{
file: fixtures.path('order_of_end_tags_5873.md'),
json: {
type: 'module',
source: 'foo',
modules: [{
textRaw: 'Title',
name: 'title',
modules: [{
textRaw: 'Subsection',
name: 'subsection',
classMethods: [{
textRaw: 'Static method: Buffer.from(array)',
type: 'classMethod',
name: 'from',
signatures: [
{
params: [{
textRaw: '`array` {Array}',
name: 'array',
type: 'Array',
}],
},
],
}],
type: 'module',
displayName: 'Subsection',
}],
type: 'module',
displayName: 'Title',
}],
},
},
{
file: fixtures.path('doc_with_yaml.md'),
json: {
type: 'module',
source: 'foo',
modules: [
{
textRaw: 'Sample Markdown with YAML info',
name: 'sample_markdown_with_yaml_info',
modules: [
{
textRaw: 'Foobar',
name: 'foobar',
meta: {
added: ['v1.0.0'],
changes: [],
},
desc: '<p>Describe <code>Foobar</code> in more detail ' +
'here.</p>',
type: 'module',
displayName: 'Foobar',
},
{
textRaw: 'Foobar II',
name: 'foobar_ii',
meta: {
added: ['v5.3.0', 'v4.2.0'],
changes: [
{ 'version': 'v4.2.0',
'pr-url': 'https://github.com/nodejs/node/pull/3276',
'description': 'The `error` parameter can now be ' +
'an arrow function.' },
],
},
desc: '<p>Describe <code>Foobar II</code> in more detail ' +
'here. fg(1)</p>',
type: 'module',
displayName: 'Foobar II',
},
{
textRaw: 'Deprecated thingy',
name: 'deprecated_thingy',
meta: {
added: ['v1.0.0'],
deprecated: ['v2.0.0'],
changes: [],
},
desc: '<p>Describe <code>Deprecated thingy</code> in more ' +
'detail here. fg(1p)</p>',
type: 'module',
displayName: 'Deprecated thingy',
},
{
textRaw: 'Something',
name: 'something',
desc: '<!-- This is not a metadata comment -->\n<p>' +
'Describe <code>Something</code> in more detail here.</p>',
type: 'module',
displayName: 'Something',
},
],
type: 'module',
displayName: 'Sample Markdown with YAML info',
},
],
},
},
{
file: fixtures.path('doc_with_backticks_in_headings.md'),
json: {
type: 'module',
source: 'foo',
modules: [
{
textRaw: 'Fhqwhgads',
name: 'fhqwhgads',
properties: [
{
name: 'fullName',
textRaw: '`Fqhqwhgads.fullName`',
},
],
classMethods: [
{
name: 'again',
signatures: [
{
params: [],
},
],
textRaw: 'Static method: `Fhqwhgads.again()`',
type: 'classMethod',
},
],
classes: [
{
textRaw: 'Class: `ComeOn`',
type: 'class',
name: 'ComeOn',
},
],
ctors: [
{
name: 'Fhqwhgads',
signatures: [
{
params: [],
},
],
textRaw: 'Constructor: `new Fhqwhgads()`',
type: 'ctor',
},
],
methods: [
{
textRaw: '`everybody.to(limit)`',
type: 'method',
name: 'to',
signatures: [{ params: [] }],
},
],
events: [
{
textRaw: "Event: `'FHQWHfest'`",
type: 'event',
name: 'FHQWHfest',
params: [],
},
],
type: 'module',
displayName: 'Fhqwhgads',
},
],
},
},
];
testData.forEach((item) => {
fs.readFile(item.file, 'utf8', common.mustSucceed((input) => {
toJSON(input, 'foo', common.mustSucceed((output) => {
assert.deepStrictEqual(output.json, item.json);
}));
}));
});