Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 66903f6

Browse filesBrowse 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: #6031 Fixes: #5955 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 3f608b1 commit 66903f6
Copy full SHA for 66903f6

File tree

Expand file treeCollapse file tree

8 files changed

+152
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

8 files changed

+152
-4
lines changed
Open diff view settings
Collapse file

‎Makefile‎

Copy file name to clipboardExpand all lines: Makefile
+2-2Lines 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
Collapse file

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

Copy file name to clipboard
+48Lines changed: 48 additions & 0 deletions
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+
});
Collapse file

‎test/doctool/test-doctool-json.js‎

Copy file name to clipboard
+78Lines changed: 78 additions & 0 deletions
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+
});
Collapse file

‎test/doctool/testcfg.py‎

Copy file name to clipboard
+7Lines changed: 7 additions & 0 deletions
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')
Collapse file
+6Lines changed: 6 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
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}
Collapse file

‎test/fixtures/sample_document.md‎

Copy file name to clipboard
+8Lines changed: 8 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
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
Collapse file

‎tools/test.py‎

Copy file name to clipboardExpand all lines: tools/test.py
+1Lines 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

Collapse file

‎vcbuild.bat‎

Copy file name to clipboardExpand all lines: vcbuild.bat
+2-2Lines 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" set noetw=1&goto arg-ok
5656
if /i "%1"=="noperfctr" set noperfctr=1&goto arg-ok
5757
if /i "%1"=="licensertf" set licensertf=1&goto arg-ok
58-
if /i "%1"=="test" set test_args=%test_args% addons sequential parallel message -J&set jslint=1&set build_addons=1&goto arg-ok
59-
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
58+
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
59+
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
6060
if /i "%1"=="test-addons" set test_args=%test_args% addons&set build_addons=1&goto arg-ok
6161
if /i "%1"=="test-simple" set test_args=%test_args% sequential parallel -J&goto arg-ok
6262
if /i "%1"=="test-message" set test_args=%test_args% message&goto arg-ok

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.