From d8cc63bf1eb2c8fcf15706d2ab79b8381960c313 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sun, 15 Oct 2017 08:56:05 +0800 Subject: [PATCH 01/11] test: add common.projectDir Implement common.projectDir which points to the project directory. --- test/common/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/common/index.js b/test/common/index.js index 05f21e25ca346a..25fbc930595883 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -59,6 +59,8 @@ exports.enoughTestCpu = Array.isArray(cpus) && (cpus.length > 1 || cpus[0].speed > 999); exports.rootDir = exports.isWindows ? 'c:\\' : '/'; +exports.projectDir = path.join(__dirname, '..', '..'); + exports.buildType = process.config.target_defaults.default_configuration; // If env var is set then enable async_hook hooks for all tests. From 43ce6daf290986264210144e85dc3c61004457b1 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sun, 15 Oct 2017 08:57:10 +0800 Subject: [PATCH 02/11] test: test make doc and verify toc --- test/sequential/test-make-doc.js | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 test/sequential/test-make-doc.js diff --git a/test/sequential/test-make-doc.js b/test/sequential/test-make-doc.js new file mode 100644 index 00000000000000..40b1cccd43fadb --- /dev/null +++ b/test/sequential/test-make-doc.js @@ -0,0 +1,60 @@ +'use strict'; + +const common = require('../common'); + +const assert = require('assert'); +const exec = require('child_process').exec; +const fs = require('fs'); +const path = require('path'); + +if (common.isWindows) { + common.skip('Do not make doc on Windows'); +} + +// Make sure all the relative links work and +// all the generated documents are linked in TOC +function verifyToc() { + const apiPath = path.join(common.projectDir, 'out', 'doc', 'api'); + const docs = fs.readdirSync(apiPath); + assert.notStrictEqual(docs.indexOf('_toc.html'), -1); + + const toc = fs.readFileSync(path.join(apiPath, '_toc.html'), 'utf8'); + const re = /href="([^/]+\.html)"/; + const globalRe = new RegExp(re, 'g'); + const links = toc.match(globalRe); + assert.notStrictEqual(links, null); + + const linkedHtmls = links.map((link) => link.match(re)[1]); + for (const html of linkedHtmls) { + assert.notStrictEqual(docs.indexOf(html), -1, `${html} does not exist`); + } + + const excludes = ['.json', '_toc', 'assets']; + const generatedHtmls = docs.filter(function(doc) { + for (const exclude of excludes) { + if (doc.includes(exclude)) { + return false; + } + } + return true; + }); + + for (const html of generatedHtmls) { + assert.notStrictEqual( + linkedHtmls.indexOf(html), + -1, + `${html} is not linked in toc`); + } +} + +exec('make doc', { + cwd: common.projectDir +}, common.mustCall(function onExit(err, stdout, stderr) { + console.log(stdout); + if (stderr.length > 0) { + console.log('stderr is not empty: '); + console.log(stderr); + } + assert.ifError(err); + verifyToc(); +})); From 48e3b30fd13fe0e8b2a5e69312db8f9433aad8b4 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 17 Oct 2017 15:31:19 +0800 Subject: [PATCH 03/11] doc projectDir --- test/common/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/common/README.md b/test/common/README.md index e2135f710efe34..93106ad076e2e1 100644 --- a/test/common/README.md +++ b/test/common/README.md @@ -337,6 +337,11 @@ original state after calling [`common.hijackStdOut()`][]. Path to the 'root' directory. either `/` or `c:\\` (windows) +### projectDir +* return [<String>] + +Path to the project directory. + ### skip(msg) * `msg` [<String>] From 882172ff25b2e6b1b5ade311ca526c334ec21250 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 17 Oct 2017 15:55:27 +0800 Subject: [PATCH 04/11] put the make doc part in Makefile --- Makefile | 3 +- test/sequential/test-make-doc.js | 74 +++++++++++++------------------- 2 files changed, 32 insertions(+), 45 deletions(-) diff --git a/Makefile b/Makefile index ddbfd0f8851394..97e324c6e1107a 100644 --- a/Makefile +++ b/Makefile @@ -200,6 +200,7 @@ else test: all $(MAKE) build-addons $(MAKE) build-addons-napi + $(MAKE) doc-only $(MAKE) cctest $(PYTHON) tools/test.py --mode=release -J \ $(CI_ASYNC_HOOKS) \ @@ -379,7 +380,7 @@ test-ci-js: | clear-stalled fi test-ci: LOGLEVEL := info -test-ci: | clear-stalled build-addons build-addons-napi +test-ci: | clear-stalled build-addons build-addons-napi doc-only out/Release/cctest --gtest_output=tap:cctest.tap $(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \ --mode=release --flaky-tests=$(FLAKY_TESTS) \ diff --git a/test/sequential/test-make-doc.js b/test/sequential/test-make-doc.js index 40b1cccd43fadb..09c1d7385d0ddf 100644 --- a/test/sequential/test-make-doc.js +++ b/test/sequential/test-make-doc.js @@ -1,9 +1,11 @@ 'use strict'; +// This tests that `make doc` generates the documentation properly. +// Note that for this test to pass, `make doc` must be run first. + const common = require('../common'); const assert = require('assert'); -const exec = require('child_process').exec; const fs = require('fs'); const path = require('path'); @@ -11,50 +13,34 @@ if (common.isWindows) { common.skip('Do not make doc on Windows'); } -// Make sure all the relative links work and -// all the generated documents are linked in TOC -function verifyToc() { - const apiPath = path.join(common.projectDir, 'out', 'doc', 'api'); - const docs = fs.readdirSync(apiPath); - assert.notStrictEqual(docs.indexOf('_toc.html'), -1); - - const toc = fs.readFileSync(path.join(apiPath, '_toc.html'), 'utf8'); - const re = /href="([^/]+\.html)"/; - const globalRe = new RegExp(re, 'g'); - const links = toc.match(globalRe); - assert.notStrictEqual(links, null); - - const linkedHtmls = links.map((link) => link.match(re)[1]); - for (const html of linkedHtmls) { - assert.notStrictEqual(docs.indexOf(html), -1, `${html} does not exist`); - } +const apiPath = path.join(common.projectDir, 'out', 'doc', 'api'); +const docs = fs.readdirSync(apiPath); +assert.ok(docs.includes('_toc.html')); + +const toc = fs.readFileSync(path.join(apiPath, '_toc.html'), 'utf8'); +const re = /href="([^/]+\.html)"/; +const globalRe = new RegExp(re, 'g'); +const links = toc.match(globalRe); +assert.notStrictEqual(links, null); + +// Test that all the relative links in the TOC of the documentation +// work and all the generated documents are linked in TOC. +const linkedHtmls = links.map((link) => link.match(re)[1]); +for (const html of linkedHtmls) { + assert.ok(docs.includes(html), `${html} does not exist`); +} - const excludes = ['.json', '_toc', 'assets']; - const generatedHtmls = docs.filter(function(doc) { - for (const exclude of excludes) { - if (doc.includes(exclude)) { - return false; - } +const excludes = ['.json', '_toc', 'assets']; +const generatedHtmls = docs.filter(function(doc) { + for (const exclude of excludes) { + if (doc.includes(exclude)) { + return false; } - return true; - }); - - for (const html of generatedHtmls) { - assert.notStrictEqual( - linkedHtmls.indexOf(html), - -1, - `${html} is not linked in toc`); } -} + return true; +}); -exec('make doc', { - cwd: common.projectDir -}, common.mustCall(function onExit(err, stdout, stderr) { - console.log(stdout); - if (stderr.length > 0) { - console.log('stderr is not empty: '); - console.log(stderr); - } - assert.ifError(err); - verifyToc(); -})); +for (const html of generatedHtmls) { + assert.ok(linkedHtmls.includes(html), `${html} is not linked in toc`); +} + \ No newline at end of file From 2ff4a775d3621a293d0372a372e4511d988a5a85 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 17 Oct 2017 16:01:54 +0800 Subject: [PATCH 05/11] fix lint --- test/sequential/test-make-doc.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/sequential/test-make-doc.js b/test/sequential/test-make-doc.js index 09c1d7385d0ddf..53acf4ee09edb7 100644 --- a/test/sequential/test-make-doc.js +++ b/test/sequential/test-make-doc.js @@ -43,4 +43,3 @@ const generatedHtmls = docs.filter(function(doc) { for (const html of generatedHtmls) { assert.ok(linkedHtmls.includes(html), `${html} is not linked in toc`); } - \ No newline at end of file From 271ff20ca4c720d9e8127ae9e323c6a0e750ee93 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 17 Oct 2017 16:05:41 +0800 Subject: [PATCH 06/11] s/doc-only/doc/ --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 97e324c6e1107a..ada5526f0223e0 100644 --- a/Makefile +++ b/Makefile @@ -200,7 +200,7 @@ else test: all $(MAKE) build-addons $(MAKE) build-addons-napi - $(MAKE) doc-only + $(MAKE) doc $(MAKE) cctest $(PYTHON) tools/test.py --mode=release -J \ $(CI_ASYNC_HOOKS) \ @@ -380,7 +380,7 @@ test-ci-js: | clear-stalled fi test-ci: LOGLEVEL := info -test-ci: | clear-stalled build-addons build-addons-napi doc-only +test-ci: | clear-stalled build-addons build-addons-napi doc out/Release/cctest --gtest_output=tap:cctest.tap $(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \ --mode=release --flaky-tests=$(FLAKY_TESTS) \ From 60c3c85b88b281ec9234b48d9c7ebf2a3a806366 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 17 Oct 2017 16:18:59 +0800 Subject: [PATCH 07/11] put make doc in build-ci --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ada5526f0223e0..399cecb0d181a0 100644 --- a/Makefile +++ b/Makefile @@ -380,7 +380,7 @@ test-ci-js: | clear-stalled fi test-ci: LOGLEVEL := info -test-ci: | clear-stalled build-addons build-addons-napi doc +test-ci: | clear-stalled build-addons build-addons-napi out/Release/cctest --gtest_output=tap:cctest.tap $(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \ --mode=release --flaky-tests=$(FLAKY_TESTS) \ @@ -556,6 +556,7 @@ docclean: build-ci: $(PYTHON) ./configure $(CONFIG_FLAGS) $(MAKE) + $(MAKE) doc run-ci: build-ci $(MAKE) test-ci From 014e360c5caf5f5c216824a6f098d86fceab3eca Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 17 Oct 2017 18:05:30 +0800 Subject: [PATCH 08/11] remove redundant slash --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 399cecb0d181a0..373e4e20f0eeb3 100644 --- a/Makefile +++ b/Makefile @@ -519,7 +519,7 @@ doc: $(NODE_EXE) doc-only $(apidoc_dirs): mkdir -p $@ -out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets/ +out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets cp $< $@ out/doc/%: doc/% From f678717f521833289337d08547e02206b4ff2de9 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 17 Oct 2017 20:36:43 +0800 Subject: [PATCH 09/11] put doc in the dependency of test-ci --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 373e4e20f0eeb3..1c70416c737500 100644 --- a/Makefile +++ b/Makefile @@ -380,7 +380,7 @@ test-ci-js: | clear-stalled fi test-ci: LOGLEVEL := info -test-ci: | clear-stalled build-addons build-addons-napi +test-ci: | clear-stalled build-addons build-addons-napi doc out/Release/cctest --gtest_output=tap:cctest.tap $(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \ --mode=release --flaky-tests=$(FLAKY_TESTS) \ @@ -556,7 +556,6 @@ docclean: build-ci: $(PYTHON) ./configure $(CONFIG_FLAGS) $(MAKE) - $(MAKE) doc run-ci: build-ci $(MAKE) test-ci From bdff9e3975e76351b60e9669cb20bad5ad83dd96 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 18 Oct 2017 13:46:06 +0800 Subject: [PATCH 10/11] fix nits --- test/sequential/test-make-doc.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/test/sequential/test-make-doc.js b/test/sequential/test-make-doc.js index 53acf4ee09edb7..06386c0c818bcb 100644 --- a/test/sequential/test-make-doc.js +++ b/test/sequential/test-make-doc.js @@ -1,23 +1,21 @@ 'use strict'; +const common = require('../common'); +if (common.isWindows) { + common.skip('`make doc` does not run on Windows'); +} // This tests that `make doc` generates the documentation properly. // Note that for this test to pass, `make doc` must be run first. -const common = require('../common'); - const assert = require('assert'); const fs = require('fs'); const path = require('path'); -if (common.isWindows) { - common.skip('Do not make doc on Windows'); -} - -const apiPath = path.join(common.projectDir, 'out', 'doc', 'api'); +const apiPath = path.resolve(common.projectDir, 'out', 'doc', 'api'); const docs = fs.readdirSync(apiPath); assert.ok(docs.includes('_toc.html')); -const toc = fs.readFileSync(path.join(apiPath, '_toc.html'), 'utf8'); +const toc = fs.readFileSync(path.resolve(apiPath, '_toc.html'), 'utf8'); const re = /href="([^/]+\.html)"/; const globalRe = new RegExp(re, 'g'); const links = toc.match(globalRe); From 2de566bc4f0b3bb88a7bad8ac59e772e3f43abae Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 18 Oct 2017 13:50:14 +0800 Subject: [PATCH 11/11] fix nits: common --- test/common/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common/index.js b/test/common/index.js index 25fbc930595883..102120e6a1f54e 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -59,7 +59,7 @@ exports.enoughTestCpu = Array.isArray(cpus) && (cpus.length > 1 || cpus[0].speed > 999); exports.rootDir = exports.isWindows ? 'c:\\' : '/'; -exports.projectDir = path.join(__dirname, '..', '..'); +exports.projectDir = path.resolve(__dirname, '..', '..'); exports.buildType = process.config.target_defaults.default_configuration;