Skip to content

Commit

Permalink
tools/doc: Add tests for the doJSON function
Browse files Browse the repository at this point in the history
Addresses nodejs#5955 on GitHub. Check that when given valid markdown it produced
valid JSON with the expected schema.
  • Loading branch information
iankronquist committed Apr 4, 2016
1 parent 524ebc7 commit 2040025
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions tools/doc/tests/test_json.js
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();

0 comments on commit 2040025

Please sign in to comment.