Skip to content

Commit 81d3985

Browse files
committed
get test-ci passing again
1 parent 3a4489a commit 81d3985

File tree

4 files changed

+67
-25
lines changed

4 files changed

+67
-25
lines changed

test/doctool/test-doctool-html.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,34 @@ try {
1111
const assert = require('assert');
1212
const { readFile } = require('fs');
1313
const fixtures = require('../common/fixtures');
14-
const toHTML = require('../../tools/doc/html.js');
14+
const html = require('../../tools/doc/html.js');
15+
const path = require('path');
16+
17+
module.paths.unshift(
18+
path.join(__dirname, '..', '..', 'tools', 'doc', 'node_modules'));
19+
const unified = require('unified');
20+
const markdown = require('remark-parse');
21+
const remark2rehype = require('remark-rehype');
22+
const raw = require('rehype-raw');
23+
const htmlStringify = require('rehype-stringify');
24+
25+
function toHTML({ input, filename, nodeVersion, analytics }, cb) {
26+
const content = unified()
27+
.use(markdown)
28+
.use(html.firstHeader)
29+
.use(html.preprocessText)
30+
.use(html.preprocessElements, { filename })
31+
.use(html.buildToc, { filename })
32+
.use(remark2rehype, { allowDangerousHTML: true })
33+
.use(raw)
34+
.use(htmlStringify)
35+
.processSync(input);
36+
37+
html.toHTML(
38+
{ input, content, filename, nodeVersion, analytics },
39+
cb
40+
);
41+
}
1542

1643
// Test data is a list of objects with two properties.
1744
// The file property is the file path.
@@ -80,7 +107,6 @@ testData.forEach(({ file, html, analyticsId }) => {
80107

81108
readFile(file, 'utf8', common.mustCall((err, input) => {
82109
assert.ifError(err);
83-
84110
toHTML(
85111
{
86112
input: input,

test/doctool/test-doctool-json.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,27 @@ try {
1010

1111
const assert = require('assert');
1212
const fs = require('fs');
13+
const path = require('path');
1314
const fixtures = require('../common/fixtures');
1415
const json = require('../../tools/doc/json.js');
1516

17+
module.paths.unshift(
18+
path.join(__dirname, '..', '..', 'tools', 'doc', 'node_modules'));
19+
const unified = require('unified');
20+
const markdown = require('remark-parse');
21+
22+
function toJSON(input, filename, cb) {
23+
function nullCompiler() {
24+
this.Compiler = (tree) => tree;
25+
}
26+
27+
unified()
28+
.use(markdown)
29+
.use(json.jsonAPI, { filename })
30+
.use(nullCompiler)
31+
.process(input, cb);
32+
}
33+
1634
// Outputs valid json with the expected fields when given simple markdown
1735
// Test data is a list of objects with two properties.
1836
// The file property is the file path.
@@ -21,15 +39,16 @@ const testData = [
2139
{
2240
file: fixtures.path('sample_document.md'),
2341
json: {
42+
type: 'module',
2443
source: 'foo',
2544
modules: [{
2645
textRaw: 'Sample Markdown',
2746
name: 'sample_markdown',
2847
modules: [{
2948
textRaw: 'Seussian Rhymes',
3049
name: 'seussian_rhymes',
31-
desc: '<ol>\n<li>fish</li>\n<li><p>fish</p>\n</li>\n<li>' +
32-
'<p>Red fish</p>\n</li>\n<li>Blue fish</li>\n</ol>\n',
50+
desc: '<ol>\n<li>fish</li>\n<li>fish</li>\n</ol>\n' +
51+
'<ul>\n<li>Red fish</li>\n<li>Blue fish</li>\n</ul>',
3352
type: 'module',
3453
displayName: 'Seussian Rhymes'
3554
}],
@@ -41,6 +60,7 @@ const testData = [
4160
{
4261
file: fixtures.path('order_of_end_tags_5873.md'),
4362
json: {
63+
type: 'module',
4464
source: 'foo',
4565
modules: [{
4666
textRaw: 'Title',
@@ -55,15 +75,10 @@ const testData = [
5575
signatures: [
5676
{
5777
params: [{
58-
textRaw: '`array` {Array} ',
78+
textRaw: '`array` {Array}',
5979
name: 'array',
6080
type: 'Array'
6181
}]
62-
},
63-
{
64-
params: [{
65-
name: 'array'
66-
}]
6782
}
6883
]
6984
}],
@@ -78,6 +93,7 @@ const testData = [
7893
{
7994
file: fixtures.path('doc_with_yaml.md'),
8095
json: {
96+
type: 'module',
8197
source: 'foo',
8298
modules: [
8399
{
@@ -92,7 +108,7 @@ const testData = [
92108
changes: []
93109
},
94110
desc: '<p>Describe <code>Foobar</code> in more detail ' +
95-
'here.</p>\n',
111+
'here.</p>',
96112
type: 'module',
97113
displayName: 'Foobar'
98114
},
@@ -110,7 +126,7 @@ const testData = [
110126
]
111127
},
112128
desc: '<p>Describe <code>Foobar II</code> in more detail ' +
113-
'here. fg(1)</p>\n',
129+
'here. fg(1)</p>',
114130
type: 'module',
115131
displayName: 'Foobar II'
116132
},
@@ -123,15 +139,15 @@ const testData = [
123139
changes: []
124140
},
125141
desc: '<p>Describe <code>Deprecated thingy</code> in more ' +
126-
'detail here. fg(1p)</p>\n',
142+
'detail here. fg(1p)</p>',
127143
type: 'module',
128144
displayName: 'Deprecated thingy'
129145
},
130146
{
131147
textRaw: 'Something',
132148
name: 'something',
133149
desc: '<!-- This is not a metadata comment -->\n<p>' +
134-
'Describe <code>Something</code> in more detail here.</p>\n',
150+
'Describe <code>Something</code> in more detail here.</p>',
135151
type: 'module',
136152
displayName: 'Something'
137153
}
@@ -147,9 +163,9 @@ const testData = [
147163
testData.forEach((item) => {
148164
fs.readFile(item.file, 'utf8', common.mustCall((err, input) => {
149165
assert.ifError(err);
150-
json(input, 'foo', common.mustCall((err, output) => {
166+
toJSON(input, 'foo', common.mustCall((err, output) => {
151167
assert.ifError(err);
152-
assert.deepStrictEqual(output, item.json);
168+
assert.deepStrictEqual(output.json, item.json);
153169
}));
154170
}));
155171
});

tools/doc/generate.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fs.readFile(filename, 'utf8', (er, input) => {
6767

6868
const content = unified()
6969
.use(markdown)
70-
.use(json.jsonAPI, { filename, outputDir })
70+
.use(json.jsonAPI, { filename })
7171
.use(html.firstHeader)
7272
.use(html.preprocessText)
7373
.use(html.preprocessElements, { filename })
@@ -77,13 +77,17 @@ fs.readFile(filename, 'utf8', (er, input) => {
7777
.use(htmlStringify)
7878
.processSync(input);
7979

80+
const basename = path.basename(filename, '.md');
81+
8082
html.toHTML(
8183
{ input, content, filename, nodeVersion, analytics },
8284
(err, html) => {
83-
const basename = path.basename(filename, '.md');
8485
const target = path.join(outputDir, `${basename}.html`);
8586
if (err) throw err;
8687
fs.writeFileSync(target, html);
8788
}
8889
);
90+
91+
const target = path.join(outputDir, `${basename}.json`);
92+
fs.writeFileSync(target, JSON.stringify(content.json, null, 2));
8993
});

tools/doc/json.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ const unified = require('unified');
2525
const common = require('./common.js');
2626
const html = require('remark-html');
2727
const select = require('unist-util-select');
28-
const path = require('path');
29-
const fs = require('fs');
3028

3129
module.exports = { jsonAPI };
3230

3331
// Unified processor: input is https://github.com/syntax-tree/mdast,
3432
// output is: https://gist.github.com/1777387.
35-
function jsonAPI({ filename, outputDir }) {
33+
function jsonAPI({ filename }) {
3634
return (tree, file) => {
3735

3836
const exampleHeading = /^example/i;
@@ -54,14 +52,12 @@ function jsonAPI({ filename, outputDir }) {
5452
}
5553
});
5654

57-
// Collect and output results.
55+
// Collect and capture results.
5856
const result = { type: 'module', source: filename };
5957
while (sections.length > 0) {
6058
doSection(sections.shift(), result);
6159
}
62-
const basename = path.basename(filename, '.md');
63-
const target = path.join(outputDir, `${basename}.json`);
64-
fs.writeFileSync(target, JSON.stringify(result, null, 2));
60+
file.json = result;
6561

6662
// Process a single section (recursively, including subsections).
6763
function doSection(section, parent) {

0 commit comments

Comments
 (0)