Skip to content

Commit 66903f6

Browse files
iankronquistFishrock123
authored andcommitted
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: #6031Fixes: #5955 Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 3f608b1 commit 66903f6

File tree

8 files changed

+152
-4
lines changed

8 files changed

+152
-4
lines changed

‎Makefile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ v8:
115115
$(MAKE) -C deps/v8 $(V8_ARCH)$(V8_BUILD_OPTIONS)
116116

117117
test: | cctest # Depends on 'all'.
118-
$(PYTHON) tools/test.py --mode=release message parallel sequential -J
118+
$(PYTHON) tools/test.py --mode=release doctool message parallel sequential -J
119119
$(MAKE) jslint
120120
$(MAKE) cpplint
121121

@@ -173,7 +173,7 @@ test-all-valgrind: test-build
173173
test-ci: | build-addons
174174
$(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \
175175
--mode=release --flaky-tests=$(FLAKY_TESTS)\
176-
$(TEST_CI_ARGS) addons message parallel sequential
176+
$(TEST_CI_ARGS) addons doctool message parallel sequential
177177

178178
test-release: test-build
179179
$(PYTHON) tools/test.py --mode=release

‎test/doctool/test-doctool-html.js‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
constassert=require('assert');
5+
constfs=require('fs');
6+
7+
consthtml=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+
consttestData=[
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+
constexpected=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+
constactual=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‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
constassert=require('assert');
5+
constfs=require('fs');
6+
7+
constjson=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+
vartestData=[
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‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
importos
2+
importsys
3+
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
4+
importtestpy
5+
6+
defGetConfiguration(context, root):
7+
returntestpy.SimpleTestConfiguration(context, root, 'doctool')
Lines changed: 6 additions & 0 deletions
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‎

Lines changed: 8 additions & 0 deletions
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‎

Lines changed: 1 addition & 0 deletions
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‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ if /i "%1"=="nosnapshot" set nosnapshot=1&goto arg-ok
5555
if /i "%1"=="noetw"setnoetw=1&goto arg-ok
5656
if /i "%1"=="noperfctr"setnoperfctr=1&goto arg-ok
5757
if /i "%1"=="licensertf"setlicensertf=1&goto arg-ok
58-
if /i "%1"=="test"settest_args=%test_args% addons sequential parallel message -J&set jslint=1&set build_addons=1&goto arg-ok
59-
if /i "%1"=="test-ci"settest_args=%test_args%%test_ci_args% -p tap --logfile test.tap addons message sequential parallel&set build_addons=1&goto arg-ok
58+
if /i "%1"=="test"settest_args=%test_args% addons doctool sequential parallel message -J&set jslint=1&set build_addons=1&goto arg-ok
59+
if /i "%1"=="test-ci"settest_args=%test_args%%test_ci_args% -p tap --logfile test.tap addons doctool message sequential parallel&set build_addons=1&goto arg-ok
6060
if /i "%1"=="test-addons"settest_args=%test_args% addons&set build_addons=1&goto arg-ok
6161
if /i "%1"=="test-simple"settest_args=%test_args% sequential parallel -J&goto arg-ok
6262
if /i "%1"=="test-message"settest_args=%test_args% message&goto arg-ok

0 commit comments

Comments
(0)