Skip to content

Commit

Permalink
fix: support egg-bin dev --cluster and --baseDir (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-horse authored and fengmk2 committed Feb 25, 2017
1 parent 0fcbe99 commit ba7d409
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,15 @@ exports.checkDeps = function* () {

exports.formatArgs = function* (cwd, args, options) {
options = options || {};
args.push('--baseDir');
args.push(cwd);
args.push('--cluster');
args.push('1');
if (!args.filter(arg => arg.startsWith('--baseDir')).length) {
args.push('--baseDir');
args.push(cwd);
}

if (!args.filter(arg => arg.startsWith('--cluster')).length) {
args.push('--cluster');
args.push('1');
}

if (options.eggPath) {
args.push(`--eggPath=${options.eggPath}`);
Expand Down
32 changes: 32 additions & 0 deletions test/egg-dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,38 @@ describe('egg-bin dev', () => {
.end(done);
});

it('should startCluster with --cluster 2', done => {
coffee.fork(eggBin, [ 'dev', '--cluster', '2' ], { cwd: appdir })
// .debug()
.expect('stdout', `{"baseDir":"${appdir}","workers":2,"customEgg":"${customEgg}"}\n`)
.expect('code', 0)
.end(done);
});

it('should startCluster with --cluster=2', done => {
coffee.fork(eggBin, [ 'dev', '--cluster=2' ], { cwd: appdir })
// .debug()
.expect('stdout', `{"baseDir":"${appdir}","workers":2,"customEgg":"${customEgg}"}\n`)
.expect('code', 0)
.end(done);
});

it('should startCluster with --baseDir base', done => {
coffee.fork(eggBin, [ 'dev', '--baseDir', 'base' ], { cwd: appdir })
// .debug()
.expect('stdout', `{"baseDir":"base","workers":1,"customEgg":"${customEgg}"}\n`)
.expect('code', 0)
.end(done);
});

it('should startCluster with --baseDir=base', done => {
coffee.fork(eggBin, [ 'dev', '--baseDir=base' ], { cwd: appdir })
// .debug()
.expect('stdout', `{"baseDir":"base","workers":1,"customEgg":"${customEgg}"}\n`)
.expect('code', 0)
.end(done);
});

it('should startCluster with custom yadan framework', done => {
const baseDir = path.join(__dirname, 'fixtures/custom-framework-app');
const customEgg = path.join(baseDir, 'node_modules', 'yadan');
Expand Down

0 comments on commit ba7d409

Please sign in to comment.