From 71c601fb2014d56c2e008284bab8b05e204e3ae1 Mon Sep 17 00:00:00 2001 From: Ian Kronquist Date: Sun, 3 Apr 2016 16:23:23 -0700 Subject: [PATCH] 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 Reviewed-By: Rich Trott --- Makefile | 4 +- test/doctool/test-doctool-html.js | 48 +++++++++++++++ test/doctool/test-doctool-json.js | 78 +++++++++++++++++++++++++ test/doctool/testcfg.py | 7 +++ test/fixtures/order_of_end_tags_5873.md | 6 ++ test/fixtures/sample_document.md | 8 +++ tools/test.py | 1 + vcbuild.bat | 4 +- 8 files changed, 152 insertions(+), 4 deletions(-) create mode 100644 test/doctool/test-doctool-html.js create mode 100644 test/doctool/test-doctool-json.js create mode 100644 test/doctool/testcfg.py create mode 100644 test/fixtures/order_of_end_tags_5873.md create mode 100644 test/fixtures/sample_document.md diff --git a/Makefile b/Makefile index 0f8648cc3678ea..2732886cdf97d6 100644 --- a/Makefile +++ b/Makefile @@ -88,7 +88,7 @@ cctest: all @out/$(BUILDTYPE)/$@ test: | cctest # Depends on 'all'. - $(PYTHON) tools/test.py --mode=release message parallel sequential -J + $(PYTHON) tools/test.py --mode=release doctool message parallel sequential -J $(MAKE) jslint $(MAKE) cpplint @@ -145,7 +145,7 @@ test-all-valgrind: test-build test-ci: | build-addons $(PYTHON) tools/test.py -p tap --logfile test.tap --mode=release --flaky-tests=$(FLAKY_TESTS) \ - $(TEST_CI_ARGS) addons message parallel sequential + $(TEST_CI_ARGS) addons doctool message parallel sequential test-release: test-build $(PYTHON) tools/test.py --mode=release diff --git a/test/doctool/test-doctool-html.js b/test/doctool/test-doctool-html.js new file mode 100644 index 00000000000000..afd89489f11ed4 --- /dev/null +++ b/test/doctool/test-doctool-html.js @@ -0,0 +1,48 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); + +const html = require('../../tools/doc/html.js'); + +// Test data is a list of objects with two properties. +// The file property is the file path. +// The html property is some html which will be generated by the doctool. +// This html will be stripped of all whitespace because we don't currently +// have an html parser. +const testData = [ + { + 'file': common.fixturesDir + '/sample_document.md', + 'html': '
  1. fish
  2. fish

  3. Redfish

  4. ' + + '
  5. Bluefish
' + }, + { + 'file': common.fixturesDir + '/order_of_end_tags_5873.md', + 'html': '

ClassMethod: Buffer.from(array) ' + + '#

' + }, +]; + +testData.forEach(function(item) { + // Normalize expected data by stripping whitespace + const expected = item.html.replace(/\s/g, ''); + + fs.readFile(item.file, 'utf8', common.mustCall(function(err, input) { + assert.ifError(err); + html(input, 'foo', 'doc/template.html', + common.mustCall(function(err, output) { + assert.ifError(err); + + const actual = output.replace(/\s/g, ''); + // Assert that the input stripped of all whitespace contains the + // expected list + assert.notEqual(actual.indexOf(expected), -1); + })); + })); +}); diff --git a/test/doctool/test-doctool-json.js b/test/doctool/test-doctool-json.js new file mode 100644 index 00000000000000..31e260fcb02d43 --- /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': '
    \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': 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); + })); + })); +}); diff --git a/test/doctool/testcfg.py b/test/doctool/testcfg.py new file mode 100644 index 00000000000000..5778d2f0c5ba5a --- /dev/null +++ b/test/doctool/testcfg.py @@ -0,0 +1,7 @@ +import os +import sys +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) +import testpy + +def GetConfiguration(context, root): + return testpy.SimpleTestConfiguration(context, root, 'doctool') diff --git a/test/fixtures/order_of_end_tags_5873.md b/test/fixtures/order_of_end_tags_5873.md new file mode 100644 index 00000000000000..3eb7dadcb32b1a --- /dev/null +++ b/test/fixtures/order_of_end_tags_5873.md @@ -0,0 +1,6 @@ +# Title + +## Subsection + +### Class Method: Buffer.from(array) +* `array` {Array} diff --git a/test/fixtures/sample_document.md b/test/fixtures/sample_document.md new file mode 100644 index 00000000000000..d1ba308b6d9c26 --- /dev/null +++ b/test/fixtures/sample_document.md @@ -0,0 +1,8 @@ +# Sample Markdown + +## Seussian Rhymes +1. fish +2. fish + +* Red fish +* Blue fish diff --git a/tools/test.py b/tools/test.py index 8e0dd33233659a..e1189bfbc28608 100755 --- a/tools/test.py +++ b/tools/test.py @@ -1427,6 +1427,7 @@ def ExpandCommand(args): 'addons', 'gc', 'debugger', + 'doctool', ] diff --git a/vcbuild.bat b/vcbuild.bat index 829900fd49acae..14c65fdcdb3bf5 100644 --- a/vcbuild.bat +++ b/vcbuild.bat @@ -55,8 +55,8 @@ if /i "%1"=="nosnapshot" set nosnapshot=1&goto arg-ok if /i "%1"=="noetw" set noetw=1&goto arg-ok if /i "%1"=="noperfctr" set noperfctr=1&goto arg-ok if /i "%1"=="licensertf" set licensertf=1&goto arg-ok -if /i "%1"=="test" set test_args=%test_args% addons sequential parallel message -J&set jslint=1&set build_addons=1&goto arg-ok -if /i "%1"=="test-ci" set test_args=%test_args% %test_ci_args% -p tap --logfile test.tap addons message sequential parallel&set build_addons=1&goto arg-ok +if /i "%1"=="test" set test_args=%test_args% addons doctool sequential parallel message -J&set jslint=1&set build_addons=1&goto arg-ok +if /i "%1"=="test-ci" set test_args=%test_args% %test_ci_args% -p tap --logfile test.tap addons doctool message sequential parallel&set build_addons=1&goto arg-ok if /i "%1"=="test-addons" set test_args=%test_args% addons&set build_addons=1&goto arg-ok if /i "%1"=="test-simple" set test_args=%test_args% sequential parallel -J&goto arg-ok if /i "%1"=="test-message" set test_args=%test_args% message&goto arg-ok