1010
1111const assert = require ( 'assert' ) ;
1212const fs = require ( 'fs' ) ;
13+ const path = require ( 'path' ) ;
1314const fixtures = require ( '../common/fixtures' ) ;
1415const json = require ( '../../tools/doc/json.js' ) ;
1516
17+ module . paths . unshift (
18+ path . join ( __dirname , '..' , '..' , 'tools' , 'doc' , 'node_modules' ) ) ;
19+ const unified = require ( 'unified' ) ;
20+ const markdown = require ( 'remark-parse' ) ;
21+
22+ function toJSON ( input , filename , cb ) {
23+ function nullCompiler ( ) {
24+ this . Compiler = ( tree ) => tree ;
25+ }
26+
27+ unified ( )
28+ . use ( markdown )
29+ . use ( json . jsonAPI , { filename } )
30+ . use ( nullCompiler )
31+ . process ( input , cb ) ;
32+ }
33+
1634// Outputs valid json with the expected fields when given simple markdown
1735// Test data is a list of objects with two properties.
1836// The file property is the file path.
@@ -21,15 +39,16 @@ const testData = [
2139 {
2240 file : fixtures . path ( 'sample_document.md' ) ,
2341 json : {
42+ type : 'module' ,
2443 source : 'foo' ,
2544 modules : [ {
2645 textRaw : 'Sample Markdown' ,
2746 name : 'sample_markdown' ,
2847 modules : [ {
2948 textRaw : 'Seussian Rhymes' ,
3049 name : 'seussian_rhymes' ,
31- desc : '<ol>\n<li>fish</li>\n<li><p> fish</p >\n</li >\n<li> ' +
32- '<p> Red fish</p>\n</ li>\n<li>Blue fish</li>\n</ol>\n ' ,
50+ desc : '<ol>\n<li>fish</li>\n<li>fish</li >\n</ol >\n' +
51+ '<ul>\n<li> Red fish</li>\n<li>Blue fish</li>\n</ul> ' ,
3352 type : 'module' ,
3453 displayName : 'Seussian Rhymes'
3554 } ] ,
@@ -41,6 +60,7 @@ const testData = [
4160 {
4261 file : fixtures . path ( 'order_of_end_tags_5873.md' ) ,
4362 json : {
63+ type : 'module' ,
4464 source : 'foo' ,
4565 modules : [ {
4666 textRaw : 'Title' ,
@@ -55,15 +75,10 @@ const testData = [
5575 signatures : [
5676 {
5777 params : [ {
58- textRaw : '`array` {Array} ' ,
78+ textRaw : '`array` {Array}' ,
5979 name : 'array' ,
6080 type : 'Array'
6181 } ]
62- } ,
63- {
64- params : [ {
65- name : 'array'
66- } ]
6782 }
6883 ]
6984 } ] ,
@@ -78,6 +93,7 @@ const testData = [
7893 {
7994 file : fixtures . path ( 'doc_with_yaml.md' ) ,
8095 json : {
96+ type : 'module' ,
8197 source : 'foo' ,
8298 modules : [
8399 {
@@ -92,7 +108,7 @@ const testData = [
92108 changes : [ ]
93109 } ,
94110 desc : '<p>Describe <code>Foobar</code> in more detail ' +
95- 'here.</p>\n ' ,
111+ 'here.</p>' ,
96112 type : 'module' ,
97113 displayName : 'Foobar'
98114 } ,
@@ -110,7 +126,7 @@ const testData = [
110126 ]
111127 } ,
112128 desc : '<p>Describe <code>Foobar II</code> in more detail ' +
113- 'here. fg(1)</p>\n ' ,
129+ 'here. fg(1)</p>' ,
114130 type : 'module' ,
115131 displayName : 'Foobar II'
116132 } ,
@@ -123,15 +139,15 @@ const testData = [
123139 changes : [ ]
124140 } ,
125141 desc : '<p>Describe <code>Deprecated thingy</code> in more ' +
126- 'detail here. fg(1p)</p>\n ' ,
142+ 'detail here. fg(1p)</p>' ,
127143 type : 'module' ,
128144 displayName : 'Deprecated thingy'
129145 } ,
130146 {
131147 textRaw : 'Something' ,
132148 name : 'something' ,
133149 desc : '<!-- This is not a metadata comment -->\n<p>' +
134- 'Describe <code>Something</code> in more detail here.</p>\n ' ,
150+ 'Describe <code>Something</code> in more detail here.</p>' ,
135151 type : 'module' ,
136152 displayName : 'Something'
137153 }
@@ -147,9 +163,9 @@ const testData = [
147163testData . forEach ( ( item ) => {
148164 fs . readFile ( item . file , 'utf8' , common . mustCall ( ( err , input ) => {
149165 assert . ifError ( err ) ;
150- json ( input , 'foo' , common . mustCall ( ( err , output ) => {
166+ toJSON ( input , 'foo' , common . mustCall ( ( err , output ) => {
151167 assert . ifError ( err ) ;
152- assert . deepStrictEqual ( output , item . json ) ;
168+ assert . deepStrictEqual ( output . json , item . json ) ;
153169 } ) ) ;
154170 } ) ) ;
155171} ) ;
0 commit comments