Skip to content

Commit 0f6146c

Browse files
iankronquistMyles Borins
authored and
Myles Borins
committed
tools: add tests for the doctool
* Test the toHTML function in html.js. Check that given valid markdown it produces the expected html. One test case will prevent regressions of #5873. * Check that when given valid markdown toJSON produces valid JSON with the expected schema. * Add doctool to the list of built in tests so it runs in CI. PR-URL: #6031 Fixes: #5955 Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 1d68bdb commit 0f6146c

8 files changed

+152
-4
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ cctest: all
8888
@out/$(BUILDTYPE)/$@
8989

9090
test: | cctest # Depends on 'all'.
91-
$(PYTHON) tools/test.py --mode=release message parallel sequential -J
91+
$(PYTHON) tools/test.py --mode=release doctool message parallel sequential -J
9292
$(MAKE) jslint
9393
$(MAKE) cpplint
9494

@@ -145,7 +145,7 @@ test-all-valgrind: test-build
145145

146146
test-ci: | build-addons
147147
$(PYTHON) tools/test.py -p tap --logfile test.tap --mode=release --flaky-tests=$(FLAKY_TESTS) \
148-
$(TEST_CI_ARGS) addons message parallel sequential
148+
$(TEST_CI_ARGS) addons doctool message parallel sequential
149149

150150
test-release: test-build
151151
$(PYTHON) tools/test.py --mode=release

test/doctool/test-doctool-html.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const fs = require('fs');
6+
7+
const html = require('../../tools/doc/html.js');
8+
9+
// Test data is a list of objects with two properties.
10+
// The file property is the file path.
11+
// The html property is some html which will be generated by the doctool.
12+
// This html will be stripped of all whitespace because we don't currently
13+
// have an html parser.
14+
const testData = [
15+
{
16+
'file': common.fixturesDir + '/sample_document.md',
17+
'html': '<ol><li>fish</li><li><p>fish</p></li><li><p>Redfish</p></li>' +
18+
'<li>Bluefish</li></ol>'
19+
},
20+
{
21+
'file': common.fixturesDir + '/order_of_end_tags_5873.md',
22+
'html': '<h3>ClassMethod: Buffer.from(array) <span> ' +
23+
'<a class="mark" href="#foo_class_method_buffer_from_array" ' +
24+
'id="foo_class_method_buffer_from_array">#</a> </span> </h3><div' +
25+
'class="signature"><ul><li><code>array</code><a ' +
26+
'href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/' +
27+
'Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a></li>' +
28+
'</ul></div>'
29+
},
30+
];
31+
32+
testData.forEach(function(item) {
33+
// Normalize expected data by stripping whitespace
34+
const expected = item.html.replace(/\s/g, '');
35+
36+
fs.readFile(item.file, 'utf8', common.mustCall(function(err, input) {
37+
assert.ifError(err);
38+
html(input, 'foo', 'doc/template.html',
39+
common.mustCall(function(err, output) {
40+
assert.ifError(err);
41+
42+
const actual = output.replace(/\s/g, '');
43+
// Assert that the input stripped of all whitespace contains the
44+
// expected list
45+
assert.notEqual(actual.indexOf(expected), -1);
46+
}));
47+
}));
48+
});

test/doctool/test-doctool-json.js

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const fs = require('fs');
6+
7+
const json = require('../../tools/doc/json.js');
8+
9+
// Outputs valid json with the expected fields when given simple markdown
10+
// Test data is a list of objects with two properties.
11+
// The file property is the file path.
12+
// The json property is some json which will be generated by the doctool.
13+
var testData = [
14+
{
15+
'file': common.fixturesDir + '/sample_document.md',
16+
'json': {
17+
'source': 'foo',
18+
'modules': [ { 'textRaw': 'Sample Markdown',
19+
'name': 'sample_markdown',
20+
'modules': [ { 'textRaw':'Seussian Rhymes',
21+
'name': 'seussian_rhymes',
22+
'desc': '<ol>\n<li>fish</li>\n<li><p>fish</p>\n</li>\n<li>' +
23+
'<p>Red fish</p>\n</li>\n<li>Blue fish</li>\n</ol>\n',
24+
'type': 'module',
25+
'displayName': 'Seussian Rhymes'
26+
} ],
27+
'type': 'module',
28+
'displayName': 'Sample Markdown'
29+
} ]
30+
}
31+
},
32+
{
33+
'file': common.fixturesDir + '/order_of_end_tags_5873.md',
34+
'json': {
35+
'source':'foo',
36+
'modules': [ {
37+
'textRaw': 'Title',
38+
'name': 'title',
39+
'modules': [ {
40+
'textRaw': 'Subsection',
41+
'name': 'subsection',
42+
'classMethods': [ {
43+
'textRaw': 'Class Method: Buffer.from(array)',
44+
'type':'classMethod',
45+
'name':'from',
46+
'signatures': [ {
47+
'params': [ {
48+
'textRaw': '`array` {Array} ',
49+
'name': 'array',
50+
'type': 'Array'
51+
} ]
52+
},
53+
{
54+
'params' : [ {
55+
'name': 'array'
56+
} ]
57+
}
58+
]
59+
} ],
60+
'type': 'module',
61+
'displayName': 'Subsection'
62+
} ],
63+
'type': 'module',
64+
'displayName': 'Title'
65+
} ]
66+
}
67+
}
68+
];
69+
70+
testData.forEach(function(item) {
71+
fs.readFile(item.file, 'utf8', common.mustCall(function(err, input) {
72+
assert.ifError(err);
73+
json(input, 'foo', common.mustCall(function(err, output) {
74+
assert.ifError(err);
75+
assert.deepStrictEqual(output, item.json);
76+
}));
77+
}));
78+
});

test/doctool/testcfg.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
import sys
3+
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
4+
import testpy
5+
6+
def GetConfiguration(context, root):
7+
return testpy.SimpleTestConfiguration(context, root, 'doctool')
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Title
2+
3+
## Subsection
4+
5+
### Class Method: Buffer.from(array)
6+
* `array` {Array}

test/fixtures/sample_document.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Sample Markdown
2+
3+
## Seussian Rhymes
4+
1. fish
5+
2. fish
6+
7+
* Red fish
8+
* Blue fish

tools/test.py

+1
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,7 @@ def ExpandCommand(args):
14271427
'addons',
14281428
'gc',
14291429
'debugger',
1430+
'doctool',
14301431
]
14311432

14321433

vcbuild.bat

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ if /i "%1"=="nosnapshot" set nosnapshot=1&goto arg-ok
5454
if /i "%1"=="noetw" set noetw=1&goto arg-ok
5555
if /i "%1"=="noperfctr" set noperfctr=1&goto arg-ok
5656
if /i "%1"=="licensertf" set licensertf=1&goto arg-ok
57-
if /i "%1"=="test" set test_args=%test_args% addons sequential parallel message -J&set jslint=1&set build_addons=1&goto arg-ok
58-
if /i "%1"=="test-ci" set test_args=%test_args% %test_ci_args% -p tap --logfile test.tap addons message sequential parallel&set build_addons=1&goto arg-ok
57+
if /i "%1"=="test" set test_args=%test_args% addons doctool sequential parallel message -J&set jslint=1&set build_addons=1&goto arg-ok
58+
if /i "%1"=="test-ci" set test_args=%test_args% %test_ci_args% -p tap --logfile test.tap addons doctool message sequential parallel&set build_addons=1&goto arg-ok
5959
if /i "%1"=="test-addons" set test_args=%test_args% addons&set build_addons=1&goto arg-ok
6060
if /i "%1"=="test-simple" set test_args=%test_args% sequential parallel -J&goto arg-ok
6161
if /i "%1"=="test-message" set test_args=%test_args% message&goto arg-ok

0 commit comments

Comments
 (0)