Skip to content

Commit 2a7c863

Browse files
vsemozhetbytaddaleax
authored andcommitted
test: modernize and correct test-doctool-html.js
PR-URL: #20676 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent d223e3c commit 2a7c863

File tree

1 file changed

+25
-34
lines changed

1 file changed

+25
-34
lines changed

test/doctool/test-doctool-html.js

+25-34
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ try {
99
}
1010

1111
const assert = require('assert');
12-
const fs = require('fs');
12+
const { readFile } = require('fs');
1313
const fixtures = require('../common/fixtures');
1414
const processIncludes = require('../../tools/doc/preprocess.js');
15-
const html = require('../../tools/doc/html.js');
15+
const toHTML = require('../../tools/doc/html.js');
1616

1717
// Test data is a list of objects with two properties.
1818
// The file property is the file path.
19-
// The html property is some html which will be generated by the doctool.
20-
// This html will be stripped of all whitespace because we don't currently
21-
// have an html parser.
19+
// The html property is some HTML which will be generated by the doctool.
20+
// This HTML will be stripped of all whitespace because we don't currently
21+
// have an HTML parser.
2222
const testData = [
2323
{
2424
file: fixtures.path('sample_document.md'),
@@ -32,8 +32,7 @@ const testData = [
3232
'id="foo_class_method_buffer_from_array">#</a> </span> </h3>' +
3333
'<ul><li><code>array</code><a ' +
3434
'href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/' +
35-
'Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a></li>' +
36-
'</ul>'
35+
'Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a></li></ul>'
3736
},
3837
{
3938
file: fixtures.path('doc_with_yaml.md'),
@@ -45,42 +44,34 @@ const testData = [
4544
'<div class="api_metadata"><span>Added in: v1.0.0</span></div> ' +
4645
'<p>Describe <code>Foobar</code> in more detail here.</p>' +
4746
'<h2>Foobar II<span><a class="mark" href="#foo_foobar_ii" ' +
48-
'id="foo_foobar_ii">#</a></span></h2>' +
49-
'<div class="api_metadata">' +
47+
'id="foo_foobar_ii">#</a></span></h2><div class="api_metadata">' +
5048
'<details class="changelog"><summary>History</summary>' +
5149
'<table><tr><th>Version</th><th>Changes</th></tr>' +
5250
'<tr><td>v5.3.0, v4.2.0</td>' +
53-
'<td><p><span>Added in: v5.3.0, v4.2.0</span></p>' +
54-
'</td></tr>' +
51+
'<td><p><span>Added in: v5.3.0, v4.2.0</span></p></td></tr>' +
5552
'<tr><td>v4.2.0</td><td><p>The <code>error</code> parameter can now be' +
56-
'an arrow function.</p></td></tr></table></details>' +
57-
'</div> ' +
53+
'an arrow function.</p></td></tr></table></details></div> ' +
5854
'<p>Describe <code>Foobar II</code> in more detail here.' +
5955
'<a href="http://man7.org/linux/man-pages/man1/fg.1.html">fg(1)</a></p>' +
6056
'<h2>Deprecated thingy<span><a class="mark" ' +
6157
'href="#foo_deprecated_thingy" id="foo_deprecated_thingy">#</a>' +
62-
'</span></h2>' +
63-
'<div class="api_metadata"><span>Added in: v1.0.0</span>' +
58+
'</span></h2><div class="api_metadata"><span>Added in: v1.0.0</span>' +
6459
'<span>Deprecated since: v2.0.0</span></div><p>Describe ' +
6560
'<code>Deprecated thingy</code> in more detail here.' +
6661
'<a href="http://man7.org/linux/man-pages/man1/fg.1p.html">fg(1p)</a>' +
67-
'</p>' +
68-
'<h2>Something<span><a class="mark" href="#foo_something" ' +
62+
'</p><h2>Something<span><a class="mark" href="#foo_something" ' +
6963
'id="foo_something">#</a></span></h2> ' +
7064
'<!-- This is not a metadata comment --> ' +
71-
'<p>Describe <code>Something</code> in more detail here. ' +
72-
'</p>'
65+
'<p>Describe <code>Something</code> in more detail here. </p>'
7366
},
7467
{
7568
file: fixtures.path('doc_with_includes.md'),
7669
html: '<!-- [start-include:doc_inc_1.md] -->' +
7770
'<p>Look <a href="doc_inc_2.html#doc_inc_2_foobar">here</a>!</p>' +
78-
'<!-- [end-include:doc_inc_1.md] -->' +
79-
'<!-- [start-include:doc_inc_2.md] -->' +
71+
'<!-- [end-include:doc_inc_1.md] --><!-- [start-include:doc_inc_2.md] -->' +
8072
'<h1>foobar<span><a class="mark" href="#doc_inc_2_foobar" ' +
8173
'id="doc_inc_2_foobar">#</a></span></h1>' +
82-
'<p>I exist and am being linked to.</p>' +
83-
'<!-- [end-include:doc_inc_2.md] -->'
74+
'<p>I exist and am being linked to.</p><!-- [end-include:doc_inc_2.md] -->'
8475
},
8576
{
8677
file: fixtures.path('sample_document.md'),
@@ -92,34 +83,34 @@ const testData = [
9283

9384
const spaces = /\s/g;
9485

95-
testData.forEach((item) => {
96-
// Normalize expected data by stripping whitespace
97-
const expected = item.html.replace(spaces, '');
98-
const includeAnalytics = typeof item.analyticsId !== 'undefined';
86+
testData.forEach(({ file, html, analyticsId }) => {
87+
// Normalize expected data by stripping whitespace.
88+
const expected = html.replace(spaces, '');
89+
const includeAnalytics = typeof analyticsId !== 'undefined';
9990

100-
fs.readFile(item.file, 'utf8', common.mustCall((err, input) => {
91+
readFile(file, 'utf8', common.mustCall((err, input) => {
10192
assert.ifError(err);
102-
processIncludes(item.file, input, common.mustCall((err, preprocessed) => {
93+
processIncludes(file, input, common.mustCall((err, preprocessed) => {
10394
assert.ifError(err);
10495

105-
html(
96+
toHTML(
10697
{
10798
input: preprocessed,
10899
filename: 'foo',
109100
nodeVersion: process.version,
110-
analytics: item.analyticsId,
101+
analytics: analyticsId,
111102
},
112103
common.mustCall((err, output) => {
113104
assert.ifError(err);
114105

115106
const actual = output.replace(spaces, '');
116-
const scriptDomain = 'google-analytics.com';
117107
// Assert that the input stripped of all whitespace contains the
118-
// expected list
108+
// expected markup.
119109
assert(actual.includes(expected));
120110

121111
// Testing the insertion of Google Analytics script when
122-
// an analytics id is provided. Should not be present by default
112+
// an analytics id is provided. Should not be present by default.
113+
const scriptDomain = 'google-analytics.com';
123114
if (includeAnalytics) {
124115
assert(actual.includes(scriptDomain),
125116
`Google Analytics script was not present in "${actual}"`);

0 commit comments

Comments
 (0)