-
Notifications
You must be signed in to change notification settings - Fork 91
feat: app.js/agent.js support async function #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| "use strict"; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments)).next()); | ||
| }); | ||
| }; | ||
| function default_1(app) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| yield wait(1000); | ||
| app.app = true; | ||
| }); | ||
| } | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.default = default_1; | ||
| function wait(timeout) { | ||
| return new Promise(resolve => setTimeout(resolve, timeout)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export default async function(app) { | ||
| await wait(1000); | ||
| app.app = true; | ||
| } | ||
|
|
||
| function wait(timeout) { | ||
| return new Promise(resolve => setTimeout(resolve, timeout)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "name": "custom-app-async-function" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| 'use strict'; | ||
|
|
||
| const co = require('co'); | ||
|
|
||
| module.exports = co.wrap(function*(app) { | ||
| yield wait(1000); | ||
| throw new Error('load async error'); | ||
| }); | ||
|
|
||
| function wait(timeout) { | ||
| return new Promise(resolve => setTimeout(resolve, timeout)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "name": "custom-app-error" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| 'use strict'; | ||
|
|
||
| const co = require('co'); | ||
|
|
||
| module.exports = co.wrap(function*(app) { | ||
| yield wait(1000); | ||
| app.app = true; | ||
| }); | ||
|
|
||
| function wait(timeout) { | ||
| return new Promise(resolve => setTimeout(resolve, timeout)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "name": "custom-app-promise" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,29 +3,83 @@ | |
| const should = require('should'); | ||
| const utils = require('../../utils'); | ||
|
|
||
| describe('test/loader/mixin/load_custom_app.test.js', function() { | ||
|
|
||
| let app; | ||
| before(function() { | ||
| app = utils.createApp('plugin'); | ||
| app.loader.loadPlugin(); | ||
| app.loader.loadConfig(); | ||
| app.loader.loadCustomApp(); | ||
| describe('test/loader/mixin/load_custom_app.test.js', () => { | ||
|
|
||
| describe('app.js as function', () => { | ||
| let app; | ||
| before(() => { | ||
| app = utils.createApp('plugin'); | ||
| app.loader.loadPlugin(); | ||
| app.loader.loadConfig(); | ||
| app.loader.loadCustomApp(); | ||
| }); | ||
| after(() => app.close()); | ||
|
|
||
| it('should load app.js', () => { | ||
| app.b.should.equal('plugin b'); | ||
| app.c.should.equal('plugin c'); | ||
| app.app.should.equal('app'); | ||
| }); | ||
|
|
||
| it('should app.js of plugin before application\'s', () => { | ||
| (app.dateB <= app.date).should.equal(true); | ||
| (app.dateC <= app.date).should.equal(true); | ||
| }); | ||
|
|
||
| it('should not load plugin that is disabled', () => { | ||
| should.not.exists(app.a); | ||
| }); | ||
| }); | ||
| after(() => app.close()); | ||
|
|
||
| it('should load app.js', function() { | ||
| app.b.should.equal('plugin b'); | ||
| app.c.should.equal('plugin c'); | ||
| app.app.should.equal('app'); | ||
| describe('app.js as function return promise', () => { | ||
| let app; | ||
| before(done => { | ||
| app = utils.createApp('custom-app-promise'); | ||
| app.loader.loadPlugin(); | ||
| app.loader.loadConfig(); | ||
| app.loader.loadCustomApp(); | ||
| app.ready(done); | ||
| }); | ||
| after(() => app.close()); | ||
|
|
||
| it('should load app.js success', () => { | ||
| app.app.should.be.true(); | ||
| }); | ||
| }); | ||
|
|
||
| it('should app.js of plugin before application\'s', function() { | ||
| (app.dateB <= app.date).should.equal(true); | ||
| (app.dateC <= app.date).should.equal(true); | ||
| describe('app.js as async function', () => { | ||
| let app; | ||
| before(done => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before(() => {
...
return app.done();
});
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个没关系吧,都一样 |
||
| app = utils.createApp('custom-app-async-function'); | ||
| app.loader.loadPlugin(); | ||
| app.loader.loadConfig(); | ||
| app.loader.loadCustomApp(); | ||
| app.ready(done); | ||
| }); | ||
| after(() => app.close()); | ||
|
|
||
| it('should load app.js success', () => { | ||
| app.app.should.be.true(); | ||
| }); | ||
| }); | ||
|
|
||
| it('should not load plugin that is disabled', function() { | ||
| should.not.exists(app.a); | ||
|
|
||
| describe('app.js load async error', () => { | ||
| let app; | ||
| after(() => app.close()); | ||
|
|
||
| it('should load app.js success', done => { | ||
| app = utils.createApp('custom-app-error'); | ||
| app.on('error', err => { | ||
| err.message.should.eql('load async error'); | ||
| done(); | ||
| }); | ||
| app.loader.loadPlugin(); | ||
| app.loader.loadConfig(); | ||
| app.loader.loadCustomApp(); | ||
| app.ready(() => { | ||
| throw new Error('should not call'); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改成 this.logger.debug 吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debug 调试起来方便吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
但是对项目开发者不方便。logger.debug 也可以通过 环境变量打开。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们把 logger.debug 换成 node 的 debug?现在 debug 不能用环境变量打开,没有作用域,而且不能应用于底层模块。还有不能单独开启 debug,开启后 info 以上都会开启。