9
9
}
10
10
11
11
const assert = require ( 'assert' ) ;
12
- const fs = require ( 'fs' ) ;
12
+ const { readFile } = require ( 'fs' ) ;
13
13
const fixtures = require ( '../common/fixtures' ) ;
14
14
const processIncludes = require ( '../../tools/doc/preprocess.js' ) ;
15
- const html = require ( '../../tools/doc/html.js' ) ;
15
+ const toHTML = require ( '../../tools/doc/html.js' ) ;
16
16
17
17
// Test data is a list of objects with two properties.
18
18
// 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.
22
22
const testData = [
23
23
{
24
24
file : fixtures . path ( 'sample_document.md' ) ,
@@ -32,8 +32,7 @@ const testData = [
32
32
'id="foo_class_method_buffer_from_array">#</a> </span> </h3>' +
33
33
'<ul><li><code>array</code><a ' +
34
34
'href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/' +
35
- 'Reference/Global_Objects/Array" class="type"><Array></a></li>' +
36
- '</ul>'
35
+ 'Reference/Global_Objects/Array" class="type"><Array></a></li></ul>'
37
36
} ,
38
37
{
39
38
file : fixtures . path ( 'doc_with_yaml.md' ) ,
@@ -45,42 +44,34 @@ const testData = [
45
44
'<div class="api_metadata"><span>Added in: v1.0.0</span></div> ' +
46
45
'<p>Describe <code>Foobar</code> in more detail here.</p>' +
47
46
'<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">' +
50
48
'<details class="changelog"><summary>History</summary>' +
51
49
'<table><tr><th>Version</th><th>Changes</th></tr>' +
52
50
'<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>' +
55
52
'<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> ' +
58
54
'<p>Describe <code>Foobar II</code> in more detail here.' +
59
55
'<a href="http://man7.org/linux/man-pages/man1/fg.1.html">fg(1)</a></p>' +
60
56
'<h2>Deprecated thingy<span><a class="mark" ' +
61
57
'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>' +
64
59
'<span>Deprecated since: v2.0.0</span></div><p>Describe ' +
65
60
'<code>Deprecated thingy</code> in more detail here.' +
66
61
'<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" ' +
69
63
'id="foo_something">#</a></span></h2> ' +
70
64
'<!-- 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>'
73
66
} ,
74
67
{
75
68
file : fixtures . path ( 'doc_with_includes.md' ) ,
76
69
html : '<!-- [start-include:doc_inc_1.md] -->' +
77
70
'<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] -->' +
80
72
'<h1>foobar<span><a class="mark" href="#doc_inc_2_foobar" ' +
81
73
'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] -->'
84
75
} ,
85
76
{
86
77
file : fixtures . path ( 'sample_document.md' ) ,
@@ -92,34 +83,34 @@ const testData = [
92
83
93
84
const spaces = / \s / g;
94
85
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' ;
99
90
100
- fs . readFile ( item . file , 'utf8' , common . mustCall ( ( err , input ) => {
91
+ readFile ( file , 'utf8' , common . mustCall ( ( err , input ) => {
101
92
assert . ifError ( err ) ;
102
- processIncludes ( item . file , input , common . mustCall ( ( err , preprocessed ) => {
93
+ processIncludes ( file , input , common . mustCall ( ( err , preprocessed ) => {
103
94
assert . ifError ( err ) ;
104
95
105
- html (
96
+ toHTML (
106
97
{
107
98
input : preprocessed ,
108
99
filename : 'foo' ,
109
100
nodeVersion : process . version ,
110
- analytics : item . analyticsId ,
101
+ analytics : analyticsId ,
111
102
} ,
112
103
common . mustCall ( ( err , output ) => {
113
104
assert . ifError ( err ) ;
114
105
115
106
const actual = output . replace ( spaces , '' ) ;
116
- const scriptDomain = 'google-analytics.com' ;
117
107
// Assert that the input stripped of all whitespace contains the
118
- // expected list
108
+ // expected markup.
119
109
assert ( actual . includes ( expected ) ) ;
120
110
121
111
// 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' ;
123
114
if ( includeAnalytics ) {
124
115
assert ( actual . includes ( scriptDomain ) ,
125
116
`Google Analytics script was not present in "${ actual } "` ) ;
0 commit comments