2016-04-04 01:23:23 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
2018-03-11 20:37:56 +01:00
|
|
|
// The doctool currently uses js-yaml from the tool/node_modules/eslint/ tree.
|
2016-06-08 11:15:36 +02:00
|
|
|
try {
|
2018-03-11 20:37:56 +01:00
|
|
|
require('../../tools/node_modules/eslint/node_modules/js-yaml');
|
2018-11-04 16:25:02 +01:00
|
|
|
} catch {
|
2017-07-01 01:29:09 +02:00
|
|
|
common.skip('missing js-yaml (eslint not present)');
|
2016-06-08 11:15:36 +02:00
|
|
|
}
|
|
|
|
|
2017-07-01 01:29:09 +02:00
|
|
|
const assert = require('assert');
|
|
|
|
const fs = require('fs');
|
2018-07-07 03:46:38 +02:00
|
|
|
const path = require('path');
|
2017-08-09 19:29:40 +02:00
|
|
|
const fixtures = require('../common/fixtures');
|
2016-04-04 01:23:23 +02:00
|
|
|
const json = require('../../tools/doc/json.js');
|
|
|
|
|
2018-07-07 03:46:38 +02:00
|
|
|
module.paths.unshift(
|
|
|
|
path.join(__dirname, '..', '..', 'tools', 'doc', 'node_modules'));
|
|
|
|
const unified = require('unified');
|
|
|
|
const markdown = require('remark-parse');
|
|
|
|
|
|
|
|
function toJSON(input, filename, cb) {
|
|
|
|
function nullCompiler() {
|
|
|
|
this.Compiler = (tree) => tree;
|
|
|
|
}
|
|
|
|
|
|
|
|
unified()
|
|
|
|
.use(markdown)
|
|
|
|
.use(json.jsonAPI, { filename })
|
|
|
|
.use(nullCompiler)
|
|
|
|
.process(input, cb);
|
|
|
|
}
|
|
|
|
|
2016-04-04 01:23:23 +02:00
|
|
|
// 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.
|
2017-01-08 23:14:16 +01:00
|
|
|
const testData = [
|
2016-04-04 01:23:23 +02:00
|
|
|
{
|
2017-08-09 19:29:40 +02:00
|
|
|
file: fixtures.path('sample_document.md'),
|
2016-05-12 22:23:07 +02:00
|
|
|
json: {
|
2018-07-07 03:46:38 +02:00
|
|
|
type: 'module',
|
2016-05-12 22:23:07 +02:00
|
|
|
source: 'foo',
|
|
|
|
modules: [{
|
|
|
|
textRaw: 'Sample Markdown',
|
|
|
|
name: 'sample_markdown',
|
|
|
|
modules: [{
|
|
|
|
textRaw: 'Seussian Rhymes',
|
|
|
|
name: 'seussian_rhymes',
|
2018-07-07 03:46:38 +02:00
|
|
|
desc: '<ol>\n<li>fish</li>\n<li>fish</li>\n</ol>\n' +
|
|
|
|
'<ul>\n<li>Red fish</li>\n<li>Blue fish</li>\n</ul>',
|
2016-05-12 22:23:07 +02:00
|
|
|
type: 'module',
|
|
|
|
displayName: 'Seussian Rhymes'
|
|
|
|
}],
|
|
|
|
type: 'module',
|
|
|
|
displayName: 'Sample Markdown'
|
|
|
|
}]
|
2016-04-04 01:23:23 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2017-08-09 19:29:40 +02:00
|
|
|
file: fixtures.path('order_of_end_tags_5873.md'),
|
2016-05-12 22:23:07 +02:00
|
|
|
json: {
|
2018-07-07 03:46:38 +02:00
|
|
|
type: 'module',
|
2016-05-12 22:23:07 +02:00
|
|
|
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: [{
|
2018-07-07 03:46:38 +02:00
|
|
|
textRaw: '`array` {Array}',
|
2016-05-12 22:23:07 +02:00
|
|
|
name: 'array',
|
|
|
|
type: 'Array'
|
|
|
|
}]
|
2016-04-04 01:23:23 +02:00
|
|
|
}
|
|
|
|
]
|
2016-05-12 22:23:07 +02:00
|
|
|
}],
|
|
|
|
type: 'module',
|
|
|
|
displayName: 'Subsection'
|
|
|
|
}],
|
|
|
|
type: 'module',
|
|
|
|
displayName: 'Title'
|
|
|
|
}]
|
2016-04-04 01:23:23 +02:00
|
|
|
}
|
2016-05-01 01:17:34 +02:00
|
|
|
},
|
|
|
|
{
|
2017-08-09 19:29:40 +02:00
|
|
|
file: fixtures.path('doc_with_yaml.md'),
|
2016-05-12 22:23:07 +02:00
|
|
|
json: {
|
2018-07-07 03:46:38 +02:00
|
|
|
type: 'module',
|
2016-05-12 22:23:07 +02:00
|
|
|
source: 'foo',
|
|
|
|
modules: [
|
2016-05-01 01:17:34 +02:00
|
|
|
{
|
2016-05-12 22:23:07 +02:00
|
|
|
textRaw: 'Sample Markdown with YAML info',
|
|
|
|
name: 'sample_markdown_with_yaml_info',
|
|
|
|
modules: [
|
2016-05-01 01:17:34 +02:00
|
|
|
{
|
2016-05-12 22:23:07 +02:00
|
|
|
textRaw: 'Foobar',
|
|
|
|
name: 'foobar',
|
|
|
|
meta: {
|
2017-01-10 20:43:57 +01:00
|
|
|
added: ['v1.0.0'],
|
|
|
|
changes: []
|
2016-05-01 01:17:34 +02:00
|
|
|
},
|
2016-05-12 22:23:07 +02:00
|
|
|
desc: '<p>Describe <code>Foobar</code> in more detail ' +
|
2018-07-07 03:46:38 +02:00
|
|
|
'here.</p>',
|
2016-05-12 22:23:07 +02:00
|
|
|
type: 'module',
|
|
|
|
displayName: 'Foobar'
|
2016-05-01 01:17:34 +02:00
|
|
|
},
|
2016-05-01 01:51:38 +02:00
|
|
|
{
|
2016-05-12 22:23:07 +02:00
|
|
|
textRaw: 'Foobar II',
|
|
|
|
name: 'foobar_ii',
|
|
|
|
meta: {
|
2017-01-10 20:43:57 +01:00
|
|
|
added: ['v5.3.0', 'v4.2.0'],
|
|
|
|
changes: [
|
2018-03-06 00:50:22 +01:00
|
|
|
{ 'version': 'v4.2.0',
|
2017-01-10 20:43:57 +01:00
|
|
|
'pr-url': 'https://github.com/nodejs/node/pull/3276',
|
2018-03-06 00:50:22 +01:00
|
|
|
'description': 'The `error` parameter can now be ' +
|
2017-01-10 20:43:57 +01:00
|
|
|
'an arrow function.'
|
|
|
|
}
|
|
|
|
]
|
2016-05-01 01:51:38 +02:00
|
|
|
},
|
2016-05-12 22:23:07 +02:00
|
|
|
desc: '<p>Describe <code>Foobar II</code> in more detail ' +
|
2018-07-07 03:46:38 +02:00
|
|
|
'here. fg(1)</p>',
|
2016-05-12 22:23:07 +02:00
|
|
|
type: 'module',
|
|
|
|
displayName: 'Foobar II'
|
2016-05-01 01:51:38 +02:00
|
|
|
},
|
2016-05-01 01:17:34 +02:00
|
|
|
{
|
2016-05-12 22:23:07 +02:00
|
|
|
textRaw: 'Deprecated thingy',
|
|
|
|
name: 'deprecated_thingy',
|
|
|
|
meta: {
|
|
|
|
added: ['v1.0.0'],
|
2017-01-10 20:43:57 +01:00
|
|
|
deprecated: ['v2.0.0'],
|
|
|
|
changes: []
|
2016-05-01 01:17:34 +02:00
|
|
|
},
|
2016-05-12 22:23:07 +02:00
|
|
|
desc: '<p>Describe <code>Deprecated thingy</code> in more ' +
|
2018-07-07 03:46:38 +02:00
|
|
|
'detail here. fg(1p)</p>',
|
2016-05-12 22:23:07 +02:00
|
|
|
type: 'module',
|
|
|
|
displayName: 'Deprecated thingy'
|
2016-05-01 01:17:34 +02:00
|
|
|
},
|
|
|
|
{
|
2016-05-12 22:23:07 +02:00
|
|
|
textRaw: 'Something',
|
|
|
|
name: 'something',
|
|
|
|
desc: '<!-- This is not a metadata comment -->\n<p>' +
|
2018-07-07 03:46:38 +02:00
|
|
|
'Describe <code>Something</code> in more detail here.</p>',
|
2016-05-12 22:23:07 +02:00
|
|
|
type: 'module',
|
|
|
|
displayName: 'Something'
|
2016-05-01 01:17:34 +02:00
|
|
|
}
|
|
|
|
],
|
2016-05-12 22:23:07 +02:00
|
|
|
type: 'module',
|
|
|
|
displayName: 'Sample Markdown with YAML info'
|
2016-05-01 01:17:34 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2020-01-10 15:03:25 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
file: fixtures.path('doc_with_backticks_in_headings.md'),
|
|
|
|
json: {
|
|
|
|
type: 'module',
|
|
|
|
source: 'foo',
|
|
|
|
modules: [
|
|
|
|
{
|
|
|
|
textRaw: 'Fhqwhgads',
|
|
|
|
name: 'fhqwhgads',
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
name: 'fullName',
|
|
|
|
textRaw: '`Fqhqwhgads.fullName`'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
classMethods: [
|
|
|
|
{
|
|
|
|
name: 'again',
|
|
|
|
signatures: [
|
|
|
|
{
|
|
|
|
params: []
|
|
|
|
}
|
|
|
|
],
|
|
|
|
textRaw: 'Class Method: `Fhqwhgads.again()`',
|
|
|
|
type: 'classMethod'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
classes: [
|
|
|
|
{
|
|
|
|
textRaw: 'Class: `ComeOn`',
|
|
|
|
type: 'class',
|
|
|
|
name: 'ComeOn'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
ctors: [
|
|
|
|
{
|
|
|
|
name: 'Fhqwhgads',
|
|
|
|
signatures: [
|
|
|
|
{
|
|
|
|
params: []
|
|
|
|
}
|
|
|
|
],
|
|
|
|
textRaw: 'Constructor: `new Fhqwhgads()`',
|
|
|
|
type: 'ctor'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
methods: [
|
|
|
|
{
|
|
|
|
textRaw: '`everybody.to(limit)`',
|
|
|
|
type: 'method',
|
|
|
|
name: 'to',
|
|
|
|
signatures: [{ params: [] }]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
events: [
|
|
|
|
{
|
|
|
|
textRaw: "Event: `'FHQWHfest'`",
|
|
|
|
type: 'event',
|
|
|
|
name: 'FHQWHfest',
|
|
|
|
params: []
|
|
|
|
}
|
|
|
|
],
|
|
|
|
type: 'module',
|
|
|
|
displayName: 'Fhqwhgads'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2016-04-04 01:23:23 +02:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2017-01-08 23:14:16 +01:00
|
|
|
testData.forEach((item) => {
|
|
|
|
fs.readFile(item.file, 'utf8', common.mustCall((err, input) => {
|
2016-04-04 01:23:23 +02:00
|
|
|
assert.ifError(err);
|
2018-07-07 03:46:38 +02:00
|
|
|
toJSON(input, 'foo', common.mustCall((err, output) => {
|
2016-04-04 01:23:23 +02:00
|
|
|
assert.ifError(err);
|
2018-07-07 03:46:38 +02:00
|
|
|
assert.deepStrictEqual(output.json, item.json);
|
2016-04-04 01:23:23 +02:00
|
|
|
}));
|
|
|
|
}));
|
|
|
|
});
|