forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-doctool-json.js
More file actions
147 lines (142 loc) · 4.13 KB
/
test-doctool-json.js
File metadata and controls
147 lines (142 loc) · 4.13 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
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
'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
// The doctool currently uses js-yaml from the tool/eslint/ tree.
try {
require('../../tools/eslint/node_modules/js-yaml');
} catch (e) {
return common.skip('missing js-yaml (eslint not present)');
}
const json = require('../../tools/doc/json.js');
// 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.
var testData = [
{
file: path.join(common.fixturesDir, 'sample_document.md'),
json: {
source: 'foo',
modules: [{
textRaw: 'Sample Markdown',
name: 'sample_markdown',
modules: [{
textRaw: 'Seussian Rhymes',
name: 'seussian_rhymes',
desc: '<ol>\n<li>fish</li>\n<li><p>fish</p>\n</li>\n<li>' +
'<p>Red fish</p>\n</li>\n<li>Blue fish</li>\n</ol>\n',
type: 'module',
displayName: 'Seussian Rhymes'
}],
type: 'module',
displayName: 'Sample Markdown'
}]
}
},
{
file: path.join(common.fixturesDir, 'order_of_end_tags_5873.md'),
json: {
source: 'foo',
modules: [{
textRaw: 'Title',
name: 'title',
modules: [{
textRaw: 'Subsection',
name: 'subsection',
classMethods: [{
textRaw: 'Class Method: Buffer.from(array)',
type: 'classMethod',
name: 'from',
signatures: [
{
params: [{
textRaw: '`array` {Array} ',
name: 'array',
type: 'Array'
}]
},
{
params: [{
name: 'array'
}]
}
]
}],
type: 'module',
displayName: 'Subsection'
}],
type: 'module',
displayName: 'Title'
}]
}
},
{
file: path.join(common.fixturesDir, 'doc_with_yaml.md'),
json: {
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']
},
desc: '<p>Describe <code>Foobar</code> in more detail ' +
'here.</p>\n',
type: 'module',
displayName: 'Foobar'
},
{
textRaw: 'Foobar II',
name: 'foobar_ii',
meta: {
added: ['v5.3.0', 'v4.2.0']
},
desc: '<p>Describe <code>Foobar II</code> in more detail ' +
'here.</p>\n',
type: 'module',
displayName: 'Foobar II'
},
{
textRaw: 'Deprecated thingy',
name: 'deprecated_thingy',
meta: {
added: ['v1.0.0'],
deprecated: ['v2.0.0']
},
desc: '<p>Describe <code>Deprecated thingy</code> in more ' +
'detail here.</p>\n',
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>\n',
type: 'module',
displayName: 'Something'
}
],
type: 'module',
displayName: 'Sample Markdown with YAML info'
}
]
}
}
];
testData.forEach(function(item) {
fs.readFile(item.file, 'utf8', common.mustCall(function(err, input) {
assert.ifError(err);
json(input, 'foo', common.mustCall(function(err, output) {
assert.ifError(err);
assert.deepStrictEqual(output, item.json);
}));
}));
});