diff options
author | Ian Kronquist <iankronquist@gmail.com> | 2016-04-03 16:23:23 -0700 |
---|---|---|
committer | silverwind <me@silverwind.io> | 2016-04-29 00:45:49 +0200 |
commit | 2e845f85016f4d4b971e534f1f50f0c3416952e3 (patch) | |
tree | d502b04d11256e38c46948c999b3c94df45f0e51 /test/doctool/test-doctool-json.js | |
parent | ded3aea449d388fad03d96f03722096a33b3743c (diff) | |
download | android-node-v8-2e845f85016f4d4b971e534f1f50f0c3416952e3.tar.gz android-node-v8-2e845f85016f4d4b971e534f1f50f0c3416952e3.tar.bz2 android-node-v8-2e845f85016f4d4b971e534f1f50f0c3416952e3.zip |
tools: add tests for the doctool
* Test the toHTML function in html.js. Check that given valid markdown
it produces the expected html. One test case will prevent regressions
of #5873.
* Check that when given valid markdown toJSON produces valid JSON with
the expected schema.
* Add doctool to the list of built in tests so it runs in CI.
PR-URL: https://github.com/nodejs/node/pull/6031
Fixes: https://github.com/nodejs/node/issues/5955
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test/doctool/test-doctool-json.js')
-rw-r--r-- | test/doctool/test-doctool-json.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/test/doctool/test-doctool-json.js b/test/doctool/test-doctool-json.js new file mode 100644 index 0000000000..31e260fcb0 --- /dev/null +++ b/test/doctool/test-doctool-json.js @@ -0,0 +1,78 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); + +const json = require('../../tools/doc/json.js'); + +// Outputs valid json with the expected fields when given simple markdown +// 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': common.fixturesDir + '/sample_document.md', + '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': common.fixturesDir + '/order_of_end_tags_5873.md', + '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', common.mustCall(function(err, input) { + assert.ifError(err); + json(input, 'foo', common.mustCall(function(err, output) { + assert.ifError(err); + assert.deepStrictEqual(output, item.json); + })); + })); +}); |