forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools/doc: Add tests for the doJSON function
Addresses nodejs#5955 on GitHub. Check that when given valid markdown it produced valid JSON with the expected schema.
- Loading branch information
1 parent
524ebc7
commit 2040025
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
'use strict'; | ||
|
||
var assert = require('assert'); | ||
var fs = require('fs'); | ||
|
||
var json = require('../json.js'); | ||
|
||
// Outputs valid json with the expected fields when given simple markdown | ||
function test_doJSON() { | ||
// Test data is a list of objects with two properties. | ||
// The file property is the file path. | ||
// The json property is some json which will be generated by the doctool. | ||
var testData = [ | ||
{ | ||
'file': 'tools/doc/tests/fixtures/sample_document.markdown', | ||
'json': { | ||
'source': 'foo', | ||
'modules': [ { 'textRaw': 'Sample Markdown', | ||
'name': 'sample_markdown', | ||
'modules': [ { 'textRaw':'Seussian Rhymes', | ||
'name': 'seussian_rhymes', | ||
'desc': '<ol>\n<li>fish</li>\n<li>' + | ||
'<p>fish</p>\n</li>\n<li>' + | ||
'<p>Red fish</p>\n</li>\n' + | ||
'<li>Blue fish</li>\n</ol>\n', | ||
'type': 'module', | ||
'displayName': 'Seussian Rhymes' | ||
} ], | ||
'type': 'module', | ||
'displayName': 'Sample Markdown' | ||
} ] | ||
} | ||
}, | ||
{ | ||
'file': 'tools/doc/tests/fixtures/order_of_end_tags_5873.markdown', | ||
'json': { | ||
'source':'foo', | ||
'modules': [ { | ||
'textRaw': 'Title', | ||
'name': 'title', | ||
'modules': [ { | ||
'textRaw': 'Subsection', | ||
'name': 'subsection', | ||
'classMethods': [ { | ||
'textRaw': 'Class Method: Buffer.from(array)', | ||
'type':'classMethod', | ||
'name':'from', | ||
'signatures': [ { | ||
'params': [ { | ||
'textRaw': '`array` {Array} ', | ||
'name': 'array', | ||
'type': 'Array' | ||
} ] | ||
}, | ||
{ | ||
'params' : [ { | ||
'name': 'array' | ||
} ] | ||
} | ||
] | ||
} ], | ||
'type': 'module', | ||
'displayName': 'Subsection' | ||
} ], | ||
'type': 'module', | ||
'displayName': 'Title' | ||
} ] | ||
} | ||
} | ||
]; | ||
|
||
testData.forEach(function(item) { | ||
fs.readFile(item.file, 'utf8', function(err, input) { | ||
json(input, 'foo', function(err, output) { | ||
if (err) throw err; | ||
assert.deepStrictEqual(output, item.json); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
test_doJSON(); |