From 20400258560146ead9b3f74881d5a245e669402b Mon Sep 17 00:00:00 2001 From: Ian Kronquist Date: Sun, 3 Apr 2016 17:15:35 -0700 Subject: [PATCH] tools/doc: Add tests for the doJSON function Addresses #5955 on GitHub. Check that when given valid markdown it produced valid JSON with the expected schema. --- tools/doc/tests/test_json.js | 82 ++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tools/doc/tests/test_json.js diff --git a/tools/doc/tests/test_json.js b/tools/doc/tests/test_json.js new file mode 100644 index 00000000000000..9851a125cac4db --- /dev/null +++ b/tools/doc/tests/test_json.js @@ -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': '
    \n
  1. fish
  2. \n
  3. ' + + '

    fish

    \n
  4. \n
  5. ' + + '

    Red fish

    \n
  6. \n' + + '
  7. Blue fish
  8. \n
\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();