summaryrefslogtreecommitdiff
path: root/test/doctool
diff options
context:
space:
mode:
authorVse Mozhet Byt <vsemozhetbyt@gmail.com>2018-05-11 17:04:12 +0300
committerVse Mozhet Byt <vsemozhetbyt@gmail.com>2018-05-14 19:21:04 +0300
commitfb939844454818055434b0635d1482d737662415 (patch)
tree6a3dc7f566a3c1e86959d896c40d5d5e9450f02c /test/doctool
parent00f395db45f20c4fd2b8ea48a6b97b5b72494c4c (diff)
downloadnode-new-fb939844454818055434b0635d1482d737662415.tar.gz
test: modernize and correct test-doctool-html.js
PR-URL: https://github.com/nodejs/node/pull/20676 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/doctool')
-rw-r--r--test/doctool/test-doctool-html.js59
1 files changed, 25 insertions, 34 deletions
diff --git a/test/doctool/test-doctool-html.js b/test/doctool/test-doctool-html.js
index 91a18d536a..185faa46f7 100644
--- a/test/doctool/test-doctool-html.js
+++ b/test/doctool/test-doctool-html.js
@@ -9,16 +9,16 @@ try {
}
const assert = require('assert');
-const fs = require('fs');
+const { readFile } = require('fs');
const fixtures = require('../common/fixtures');
const processIncludes = require('../../tools/doc/preprocess.js');
-const html = require('../../tools/doc/html.js');
+const toHTML = require('../../tools/doc/html.js');
// Test data is a list of objects with two properties.
// The file property is the file path.
-// The html property is some html which will be generated by the doctool.
-// This html will be stripped of all whitespace because we don't currently
-// have an html parser.
+// The html property is some HTML which will be generated by the doctool.
+// This HTML will be stripped of all whitespace because we don't currently
+// have an HTML parser.
const testData = [
{
file: fixtures.path('sample_document.md'),
@@ -32,8 +32,7 @@ const testData = [
'id="foo_class_method_buffer_from_array">#</a> </span> </h3>' +
'<ul><li><code>array</code><a ' +
'href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/' +
- 'Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a></li>' +
- '</ul>'
+ 'Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a></li></ul>'
},
{
file: fixtures.path('doc_with_yaml.md'),
@@ -45,42 +44,34 @@ const testData = [
'<div class="api_metadata"><span>Added in: v1.0.0</span></div> ' +
'<p>Describe <code>Foobar</code> in more detail here.</p>' +
'<h2>Foobar II<span><a class="mark" href="#foo_foobar_ii" ' +
- 'id="foo_foobar_ii">#</a></span></h2>' +
- '<div class="api_metadata">' +
+ 'id="foo_foobar_ii">#</a></span></h2><div class="api_metadata">' +
'<details class="changelog"><summary>History</summary>' +
'<table><tr><th>Version</th><th>Changes</th></tr>' +
'<tr><td>v5.3.0, v4.2.0</td>' +
- '<td><p><span>Added in: v5.3.0, v4.2.0</span></p>' +
- '</td></tr>' +
+ '<td><p><span>Added in: v5.3.0, v4.2.0</span></p></td></tr>' +
'<tr><td>v4.2.0</td><td><p>The <code>error</code> parameter can now be' +
- 'an arrow function.</p></td></tr></table></details>' +
- '</div> ' +
+ 'an arrow function.</p></td></tr></table></details></div> ' +
'<p>Describe <code>Foobar II</code> in more detail here.' +
'<a href="http://man7.org/linux/man-pages/man1/fg.1.html">fg(1)</a></p>' +
'<h2>Deprecated thingy<span><a class="mark" ' +
'href="#foo_deprecated_thingy" id="foo_deprecated_thingy">#</a>' +
- '</span></h2>' +
- '<div class="api_metadata"><span>Added in: v1.0.0</span>' +
+ '</span></h2><div class="api_metadata"><span>Added in: v1.0.0</span>' +
'<span>Deprecated since: v2.0.0</span></div><p>Describe ' +
'<code>Deprecated thingy</code> in more detail here.' +
'<a href="http://man7.org/linux/man-pages/man1/fg.1p.html">fg(1p)</a>' +
- '</p>' +
- '<h2>Something<span><a class="mark" href="#foo_something" ' +
+ '</p><h2>Something<span><a class="mark" href="#foo_something" ' +
'id="foo_something">#</a></span></h2> ' +
'<!-- This is not a metadata comment --> ' +
- '<p>Describe <code>Something</code> in more detail here. ' +
- '</p>'
+ '<p>Describe <code>Something</code> in more detail here. </p>'
},
{
file: fixtures.path('doc_with_includes.md'),
html: '<!-- [start-include:doc_inc_1.md] -->' +
'<p>Look <a href="doc_inc_2.html#doc_inc_2_foobar">here</a>!</p>' +
- '<!-- [end-include:doc_inc_1.md] -->' +
- '<!-- [start-include:doc_inc_2.md] -->' +
+ '<!-- [end-include:doc_inc_1.md] --><!-- [start-include:doc_inc_2.md] -->' +
'<h1>foobar<span><a class="mark" href="#doc_inc_2_foobar" ' +
'id="doc_inc_2_foobar">#</a></span></h1>' +
- '<p>I exist and am being linked to.</p>' +
- '<!-- [end-include:doc_inc_2.md] -->'
+ '<p>I exist and am being linked to.</p><!-- [end-include:doc_inc_2.md] -->'
},
{
file: fixtures.path('sample_document.md'),
@@ -92,34 +83,34 @@ const testData = [
const spaces = /\s/g;
-testData.forEach((item) => {
- // Normalize expected data by stripping whitespace
- const expected = item.html.replace(spaces, '');
- const includeAnalytics = typeof item.analyticsId !== 'undefined';
+testData.forEach(({ file, html, analyticsId }) => {
+ // Normalize expected data by stripping whitespace.
+ const expected = html.replace(spaces, '');
+ const includeAnalytics = typeof analyticsId !== 'undefined';
- fs.readFile(item.file, 'utf8', common.mustCall((err, input) => {
+ readFile(file, 'utf8', common.mustCall((err, input) => {
assert.ifError(err);
- processIncludes(item.file, input, common.mustCall((err, preprocessed) => {
+ processIncludes(file, input, common.mustCall((err, preprocessed) => {
assert.ifError(err);
- html(
+ toHTML(
{
input: preprocessed,
filename: 'foo',
nodeVersion: process.version,
- analytics: item.analyticsId,
+ analytics: analyticsId,
},
common.mustCall((err, output) => {
assert.ifError(err);
const actual = output.replace(spaces, '');
- const scriptDomain = 'google-analytics.com';
// Assert that the input stripped of all whitespace contains the
- // expected list
+ // expected markup.
assert(actual.includes(expected));
// Testing the insertion of Google Analytics script when
- // an analytics id is provided. Should not be present by default
+ // an analytics id is provided. Should not be present by default.
+ const scriptDomain = 'google-analytics.com';
if (includeAnalytics) {
assert(actual.includes(scriptDomain),
`Google Analytics script was not present in "${actual}"`);