From e24b0ce2fe0911d9fd99847daa2760c9a10aab4d Mon Sep 17 00:00:00 2001 From: popomore Date: Sat, 3 Jun 2017 02:12:54 +0800 Subject: [PATCH 1/6] test: add doc test - improve jsdoc - fix broken links --- docs/source/_data/guide_toc.yml | 2 +- lib/application.js | 11 ++++++++--- lib/core/messenger.js | 3 +++ package.json | 1 + test/doc.test.js | 21 +++++++++++++++++++++ 5 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 test/doc.test.js diff --git a/docs/source/_data/guide_toc.yml b/docs/source/_data/guide_toc.yml index d6e767962b..964e47e812 100644 --- a/docs/source/_data/guide_toc.yml +++ b/docs/source/_data/guide_toc.yml @@ -39,7 +39,7 @@ Advanced: Cluster Client: /advanced/cluster-client.html View Plugin: /advanced/view-plugin.html Community: - Plugin List: /plugins + Plugin List: /plugins/ Contributing: /contributing.html Resource: /resource.html # Member Guide: /member_guide.html diff --git a/lib/application.js b/lib/application.js index 8927ce1a4f..36609eba59 100644 --- a/lib/application.js +++ b/lib/application.js @@ -189,13 +189,18 @@ class Application extends EggApplication { } /** - * The helper class, `app/helper` will be loaded to it's prototype, - * then you can use all method on `ctx.helper` + * reference to {@link Helper} * @member {Helper} Application#Helper */ get Helper() { if (!this[HELPER]) { - this[HELPER] = class Helper extends this.BaseContextClass {}; + /** + * The Helper class which can be used as utility function. + * Files from `${baseDir}/app/helper` will be loaded to the prototype of Helper, + * then you can use all method on `ctx.helper` that is a instance of Helper. + */ + class Helper extends this.BaseContextClass {} + this[HELPER] = Helper; } return this[HELPER]; } diff --git a/lib/core/messenger.js b/lib/core/messenger.js index b7a8cdca36..930a0ae28e 100644 --- a/lib/core/messenger.js +++ b/lib/core/messenger.js @@ -5,6 +5,9 @@ const is = require('is-type-of'); const sendmessage = require('sendmessage'); const EventEmitter = require('events'); +/** + * Communication between app worker and agent worker by IPC channel + */ class Messenger extends EventEmitter { constructor() { diff --git a/package.json b/package.json index b0d693e007..91f486e159 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "egg-view-nunjucks": "^2.1.2", "eslint": "^3.19.0", "eslint-config-egg": "^4.2.0", + "findlinks": "^1.1.0", "formstream": "^1.1.0", "glob": "^7.1.2", "mz-modules": "^1.0.0", diff --git a/test/doc.test.js b/test/doc.test.js new file mode 100644 index 0000000000..1d4ca068a3 --- /dev/null +++ b/test/doc.test.js @@ -0,0 +1,21 @@ +'use strict'; + +const cp = require('child_process'); +const sleep = require('mz-modules/sleep'); +const findlinks = require('findlinks'); +const assert = require('assert'); + +describe.only('test/doc.test.js', () => { + + let proc; + before(function* () { + proc = cp.fork(require.resolve('egg-doctools/bin/_doctools'), [ 'server' ]); + yield sleep(10000); + }); + after(() => proc.kill()); + + it('should no broken url', function* () { + const result = yield findlinks({ src: 'http://localhost:4000', logger: console }); + assert(result.fail === 0); + }); +}); From 4427ea5a40ae21080576f5594e4f812448aa4192 Mon Sep 17 00:00:00 2001 From: popomore Date: Sat, 3 Jun 2017 02:54:04 +0800 Subject: [PATCH 2/6] f --- package.json | 1 + test/doc.test.js | 22 +++++++++++++------ .../apps/docapp/app/middleware/koastatic.js | 7 ++++++ .../apps/docapp/config/config.default.js | 8 +++++++ test/fixtures/apps/docapp/package.json | 3 +++ 5 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 test/fixtures/apps/docapp/app/middleware/koastatic.js create mode 100644 test/fixtures/apps/docapp/config/config.default.js create mode 100644 test/fixtures/apps/docapp/package.json diff --git a/package.json b/package.json index 91f486e159..fa21061952 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "findlinks": "^1.1.0", "formstream": "^1.1.0", "glob": "^7.1.2", + "koa-static": "^3.0.0", "mz-modules": "^1.0.0", "pedding": "^1.1.0", "spy": "^1.0.0", diff --git a/test/doc.test.js b/test/doc.test.js index 1d4ca068a3..317736abe5 100644 --- a/test/doc.test.js +++ b/test/doc.test.js @@ -1,21 +1,29 @@ 'use strict'; -const cp = require('child_process'); -const sleep = require('mz-modules/sleep'); +const path = require('path'); const findlinks = require('findlinks'); const assert = require('assert'); +const runscript = require('runscript'); +const utils = require('./utils'); describe.only('test/doc.test.js', () => { - let proc; + let app; before(function* () { - proc = cp.fork(require.resolve('egg-doctools/bin/_doctools'), [ 'server' ]); - yield sleep(10000); + yield runscript('doctools build', { cwd: path.dirname(__dirname) }); }); - after(() => proc.kill()); + before(function* () { + app = utils.cluster({ + baseDir: 'apps/docapp', + }); + app.coverage(false); + yield app.ready(); + }); + after(() => app.close()); it('should no broken url', function* () { - const result = yield findlinks({ src: 'http://localhost:4000', logger: console }); + console.log(app.url); + const result = yield findlinks({ src: app.url, logger: console }); assert(result.fail === 0); }); }); diff --git a/test/fixtures/apps/docapp/app/middleware/koastatic.js b/test/fixtures/apps/docapp/app/middleware/koastatic.js new file mode 100644 index 0000000000..975e1bbd4b --- /dev/null +++ b/test/fixtures/apps/docapp/app/middleware/koastatic.js @@ -0,0 +1,7 @@ +'use strict'; + +const path = require('path'); + +module.exports = () => { + return require('koa-static')(path.join(process.cwd(), 'run/doctools/public')); +}; diff --git a/test/fixtures/apps/docapp/config/config.default.js b/test/fixtures/apps/docapp/config/config.default.js new file mode 100644 index 0000000000..de6604be96 --- /dev/null +++ b/test/fixtures/apps/docapp/config/config.default.js @@ -0,0 +1,8 @@ +'use strict'; + +const path = require('path'); + +module.exports = { + keys: 'test key', + middleware: [ 'koastatic' ], +}; diff --git a/test/fixtures/apps/docapp/package.json b/test/fixtures/apps/docapp/package.json new file mode 100644 index 0000000000..08811b3e64 --- /dev/null +++ b/test/fixtures/apps/docapp/package.json @@ -0,0 +1,3 @@ +{ + "name": "docapp" +} From d524c0b18014070978557d47252c0809b980fd0e Mon Sep 17 00:00:00 2001 From: popomore Date: Sun, 4 Jun 2017 23:28:21 +0800 Subject: [PATCH 3/6] f --- test/doc.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/doc.test.js b/test/doc.test.js index 317736abe5..6703641f49 100644 --- a/test/doc.test.js +++ b/test/doc.test.js @@ -6,7 +6,7 @@ const assert = require('assert'); const runscript = require('runscript'); const utils = require('./utils'); -describe.only('test/doc.test.js', () => { +describe('test/doc.test.js', () => { let app; before(function* () { From 6b26b1f10cdd5be8d66cba098871ce36da7299bd Mon Sep 17 00:00:00 2001 From: popomore Date: Mon, 5 Jun 2017 00:41:22 +0800 Subject: [PATCH 4/6] f --- test/doc.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/doc.test.js b/test/doc.test.js index 6703641f49..90393bfda0 100644 --- a/test/doc.test.js +++ b/test/doc.test.js @@ -22,7 +22,6 @@ describe('test/doc.test.js', () => { after(() => app.close()); it('should no broken url', function* () { - console.log(app.url); const result = yield findlinks({ src: app.url, logger: console }); assert(result.fail === 0); }); From 1c758477a4dbf15462e2d47e06e41a2e26351a0a Mon Sep 17 00:00:00 2001 From: popomore Date: Mon, 5 Jun 2017 01:53:29 +0800 Subject: [PATCH 5/6] f --- test/doc.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/doc.test.js b/test/doc.test.js index 90393bfda0..3e80855d18 100644 --- a/test/doc.test.js +++ b/test/doc.test.js @@ -6,6 +6,8 @@ const assert = require('assert'); const runscript = require('runscript'); const utils = require('./utils'); +if (process.platform === 'win32') return; + describe('test/doc.test.js', () => { let app; From 050ed073410eeae99185cd822d108bf4f15c6a44 Mon Sep 17 00:00:00 2001 From: popomore Date: Mon, 5 Jun 2017 02:12:28 +0800 Subject: [PATCH 6/6] f --- test/doc.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/doc.test.js b/test/doc.test.js index 3e80855d18..4db07209c7 100644 --- a/test/doc.test.js +++ b/test/doc.test.js @@ -6,10 +6,10 @@ const assert = require('assert'); const runscript = require('runscript'); const utils = require('./utils'); -if (process.platform === 'win32') return; - describe('test/doc.test.js', () => { + if (process.platform === 'win32') return; + let app; before(function* () { yield runscript('doctools build', { cwd: path.dirname(__dirname) });