Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cmd/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class StartCommand extends Command {
// check start status
yield this.checkStatus(argv);
} else {
options.stdio = options.stdio || 'inherit';
options.stdio = [ 'inherit', 'inherit', 'inherit', 'ipc' ];
debug('Run spawn `node %s`', eggArgs.join(' '));
const child = this.child = spawn('node', eggArgs, options);
child.once('exit', code => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"devDependencies": {
"autod": "^3.0.1",
"co": "^4.6.0",
"coffee": "^4.1.0",
"egg": "^1.11.0",
"egg-bin": "^4.3.5",
Expand Down
36 changes: 36 additions & 0 deletions test/fixtures/ipc-bin/start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

const co = require('co');

const BaseStartCommand = require('../../../lib/cmd/start');

class StartCommand extends BaseStartCommand {
* run(context) {
yield super.run(context);
const child = this.child;
child.on('message', msg => {
if (msg && msg.action === 'egg-ready') {
console.log('READY!!!');
}
});
}
}

const start = new StartCommand();

co(function* () {
yield start.run({
argv: {
framework: 'custom-framework',
_: [ process.env.BASE_DIR ],
workers: 2,
title: 'egg-server-example',
},
cwd: process.env.BASE_DIR,
execArgv: [],
env: {
PATH: process.env.PATH,
},
});
});

23 changes: 22 additions & 1 deletion test/start.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('test/start.test.js', () => {
yield utils.cleanup(fixturePath);
});

after(function* () {
afterEach(function* () {
app.proc.kill('SIGTERM');
yield utils.cleanup(fixturePath);
});
Expand All @@ -57,6 +57,27 @@ describe('test/start.test.js', () => {
const result = yield httpclient.request('http://127.0.0.1:7001');
assert(result.data.toString() === 'hi, egg');
});

it('should get ready', function* () {
app = coffee.fork(path.join(__dirname, './fixtures/ipc-bin/start.js'), [], {
env: {
BASE_DIR: fixturePath,
PATH: process.env.PATH,
},
});
// app.debug();
app.expect('code', 0);

yield sleep(waitTime);

assert(app.stderr === '');
assert(app.stdout.includes('READY!!!'));
assert(app.stdout.includes('--title=egg-server-example'));
assert(app.stdout.includes('"title":"egg-server-example"'));
assert(app.stdout.match(/custom-framework started on http:\/\/127\.0\.0\.1:7001/));
assert(app.stdout.includes('app_worker#2:'));
assert(!app.stdout.includes('app_worker#3:'));
});
});

describe('child exit with 1', () => {
Expand Down