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{
2240file : fixtures . path ( 'sample_document.md' ) ,
2341json : {
42+ type : 'module' ,
2443source : 'foo' ,
2544modules : [ {
2645textRaw : 'Sample Markdown' ,
2746name : 'sample_markdown' ,
2847modules : [ {
2948textRaw : 'Seussian Rhymes' ,
3049name : '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> ' ,
3352type : 'module' ,
3453displayName : 'Seussian Rhymes'
3554} ] ,
@@ -41,6 +60,7 @@ const testData = [
4160{
4261file : fixtures . path ( 'order_of_end_tags_5873.md' ) ,
4362json : {
63+ type : 'module' ,
4464source : 'foo' ,
4565modules : [ {
4666textRaw : 'Title' ,
@@ -55,15 +75,10 @@ const testData = [
5575signatures : [
5676{
5777params : [ {
58- textRaw : '`array`{Array} ' ,
78+ textRaw : '`array`{Array}' ,
5979name : 'array' ,
6080type : 'Array'
6181} ]
62- } ,
63- {
64- params : [ {
65- name : 'array'
66- } ]
6782}
6883]
6984} ] ,
@@ -78,6 +93,7 @@ const testData = [
7893{
7994file : fixtures . path ( 'doc_with_yaml.md' ) ,
8095json : {
96+ type : 'module' ,
8197source : 'foo' ,
8298modules : [
8399{
@@ -92,7 +108,7 @@ const testData = [
92108changes : [ ]
93109} ,
94110desc : '<p>Describe <code>Foobar</code> in more detail ' +
95- 'here.</p>\n ' ,
111+ 'here.</p>' ,
96112type : 'module' ,
97113displayName : 'Foobar'
98114} ,
@@ -110,7 +126,7 @@ const testData = [
110126]
111127} ,
112128desc : '<p>Describe <code>Foobar II</code> in more detail ' +
113- 'here. fg(1)</p>\n ' ,
129+ 'here. fg(1)</p>' ,
114130type : 'module' ,
115131displayName : 'Foobar II'
116132} ,
@@ -123,15 +139,15 @@ const testData = [
123139changes : [ ]
124140} ,
125141desc : '<p>Describe <code>Deprecated thingy</code> in more ' +
126- 'detail here. fg(1p)</p>\n ' ,
142+ 'detail here. fg(1p)</p>' ,
127143type : 'module' ,
128144displayName : 'Deprecated thingy'
129145} ,
130146{
131147textRaw : 'Something' ,
132148name : 'something' ,
133149desc : '<!-- 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>' ,
135151type : 'module' ,
136152displayName : 'Something'
137153}
@@ -147,9 +163,9 @@ const testData = [
147163testData . forEach ( ( item ) => {
148164fs . readFile ( item . file , 'utf8' , common . mustCall ( ( err , input ) => {
149165assert . ifError ( err ) ;
150- json ( input , 'foo' , common . mustCall ( ( err , output ) => {
166+ toJSON ( input , 'foo' , common . mustCall ( ( err , output ) => {
151167assert . ifError ( err ) ;
152- assert . deepStrictEqual ( output , item . json ) ;
168+ assert . deepStrictEqual ( output . json , item . json ) ;
153169} ) ) ;
154170} ) ) ;
155171} ) ;
0 commit comments