Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
popomore committed Jun 16, 2017
1 parent cb1c5d5 commit 3a9965b
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 38 deletions.
9 changes: 5 additions & 4 deletions lib/cmd/cov.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class CovCommand extends Command {
const outputDir = path.join(cwd, 'node_modules/.nyc_output');
yield rimraf(outputDir);

process.env.NODE_ENV = 'test';
const opt = {
cwd,
execArgv,
Expand All @@ -79,8 +80,8 @@ class CovCommand extends Command {
* @return {Array} args for nyc
* @protected
*/
getCovArgs() {
const covArgs = [
getCovArgs(context) {
let covArgs = [
// '--show-process-tree',
// instrument all files in nyc process and cache to disk,
// Then in mocha process, read instrumented files from cache.
Expand All @@ -99,8 +100,8 @@ class CovCommand extends Command {
covArgs.push('-x');
covArgs.push(exclude);
}
covArgs.push(require.resolve('../../bin/egg-bin'));
covArgs.push('test');
covArgs.push(require.resolve('mocha/bin/_mocha'));
covArgs = covArgs.concat(this.formatTestArgs(context));
return covArgs;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/cmd/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ class TestCommand extends Command {

* run(context) {
process.env.NODE_ENV = 'test';
const testArgs = this.formatTestArgs(context);
const opt = {
env: Object.assign({}, process.env),
execArgv: context.execArgv,
};
const mochaFile = require.resolve('mocha/bin/_mocha');
const testArgs = this.formatTestArgs(context);
debug('run test: %s %s', mochaFile, testArgs.join(' '));
yield this.helper.forkNode(mochaFile, testArgs, opt);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"cross-env": "^3.1.3",
"egg-ci": "^1.7.0",
"enzyme": "^2.0.0",
"eslint": "^4.0.0",
"eslint": "^3.0.0",
"eslint-config-egg": "^4.2.1",
"jsdom": "^8.0.1",
"mm": "^2.1.0",
Expand Down
18 changes: 9 additions & 9 deletions test/egg-bin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ describe('test/egg-bin.test.js', () => {
it('should show version', done => {
coffee.fork(eggBin, [ '--version' ], { cwd })
// .debug()
.expect('stdout', /\d+\.\d+\.\d+/)
.expect('code', 0)
.end(done);
.expect('stdout', /\d+\.\d+\.\d+/)
.expect('code', 0)
.end(done);
});

it('should show help', done => {
coffee.fork(eggBin, [ '--help' ], { cwd })
// .debug()
.expect('stdout', /Usage: .*egg-bin.* \[command] \[options]/)
.expect('code', 0)
.end(done);
.expect('stdout', /Usage: .*egg-bin.* \[command] \[options]/)
.expect('code', 0)
.end(done);
});

it('should show help when command not exists', done => {
coffee.fork(eggBin, [ 'not-exists' ], { cwd })
// .debug()
.expect('stdout', /Usage: .*egg-bin.* \[command] \[options]/)
.expect('code', 0)
.end(done);
.expect('stdout', /Usage: .*egg-bin.* \[command] \[options]/)
.expect('code', 0)
.end(done);
});
});
});
15 changes: 4 additions & 11 deletions test/lib/cmd/cov.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe.only('test/lib/cmd/cov.test.js', () => {
.expect('stdout', /a\.test\.js/)
.expect('stdout', /b[\/|\\]b\.test\.js/)
.notExpect('stdout', /a.js/)
.expect('stdout', /Statements {3}: [\d\.]+% \( 22[\/|\\]23 \)/)
.expect('stdout', /Statements {3}: 80% \( 4[\/|\\]5 \)/)
.expect('code', 0)
.end(err => {
assert.ifError(err);
Expand All @@ -33,14 +33,14 @@ describe.only('test/lib/cmd/cov.test.js', () => {

it('should success with COV_EXCLUDES', function* () {
mm(process.env, 'TESTS', 'test/**/*.test.js');
mm(process.env, 'COV_EXCLUDES', 'ignore/**');
mm(process.env, 'COV_EXCLUDES', 'ignore/*');
yield coffee.fork(eggBin, [ 'cov' ], { cwd })
.debug()
// .debug()
.expect('stdout', /should success/)
.expect('stdout', /a\.test\.js/)
.expect('stdout', /b[\/|\\]b\.test\.js/)
.notExpect('stdout', /a.js/)
.expect('stdout', /Statements {3}: [\d\.]+% \( \d+[\/|\\]\d+ \)/)
.expect('stdout', /Statements {3}: 75% \( 3[\/|\\]4 \)/)
.expect('code', 0)
.end();
assert(fs.existsSync(path.join(cwd, 'coverage/coverage-final.json')));
Expand All @@ -52,9 +52,7 @@ describe.only('test/lib/cmd/cov.test.js', () => {

it('should success with -x to ignore files', function* () {
yield coffee.fork(eggBin, [ 'cov', '-x', 'ignore/*', 'test/**/*.test.js' ], { cwd })
.coverage(false)
// .debug()
.expect('stdout', /[\/|\\]test[\/|\\]fixtures[\/|\\]test-files[\/|\\]\.tmp true/)
.expect('stdout', /should success/)
.expect('stdout', /a\.test\.js/)
.expect('stdout', /b[\/|\\]b\.test\.js/)
Expand All @@ -65,15 +63,13 @@ describe.only('test/lib/cmd/cov.test.js', () => {
assert(fs.existsSync(path.join(cwd, 'coverage/coverage-final.json')));
assert(fs.existsSync(path.join(cwd, 'coverage/lcov-report/index.html')));
assert(fs.existsSync(path.join(cwd, 'coverage/lcov.info')));
assert(!fs.existsSync(path.join(cwd, '.tmp')));
const lcov = fs.readFileSync(path.join(cwd, 'coverage/lcov.info'), 'utf8');
assert(!/ignore[\/|\\]a.js/.test(lcov));
});

it('should fail when test fail', done => {
mm(process.env, 'TESTS', 'test/fail.js');
coffee.fork(eggBin, [ 'cov' ], { cwd })
.coverage(false)
// .debug()
.expect('stdout', /1\) should fail/)
.expect('stdout', /1 failing/)
Expand All @@ -84,7 +80,6 @@ describe.only('test/lib/cmd/cov.test.js', () => {
it('should fail when test fail with power-assert', done => {
mm(process.env, 'TESTS', 'test/power-assert-fail.js');
coffee.fork(eggBin, [ 'cov' ], { cwd })
.coverage(false)
// .debug()
.expect('stdout', /1\) should fail/)
.expect('stdout', /1 failing/)
Expand All @@ -96,7 +91,6 @@ describe.only('test/lib/cmd/cov.test.js', () => {
it('should warn when require intelli-espower-loader', done => {
mm(process.env, 'TESTS', 'test/power-assert-fail.js');
coffee.fork(eggBin, [ 'cov', '-r', 'intelli-espower-loader' ], { cwd })
.coverage(false)
// .debug()
.expect('stderr', /manually require `intelli-espower-loader`/)
.expect('stdout', /1\) should fail/)
Expand All @@ -111,7 +105,6 @@ describe.only('test/lib/cmd/cov.test.js', () => {
const cwd = path.join(__dirname, '../../fixtures/prerequire');
yield coffee.fork(eggBin, [ 'cov' ], { cwd })
// .debug()
.coverage(false)
.expect('code', 0)
.end();
});
Expand Down
8 changes: 4 additions & 4 deletions test/lib/cmd/debug.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ describe('test/lib/cmd/debug.test.js', () => {
it('should auto detect available port', done => {
coffee.fork(eggBin, [ 'debug' ], { cwd })
// .debug()
.expect('stdout', /,"workers":1/)
.expect('stderr', /\[egg-bin] server port 7001 is in use/)
.expect('code', 0)
.end(done);
.expect('stdout', /,"workers":1/)
.expect('stderr', /\[egg-bin] server port 7001 is in use/)
.expect('code', 0)
.end(done);
});
});
});
8 changes: 4 additions & 4 deletions test/lib/cmd/dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('test/lib/cmd/dev.test.js', () => {
.expect('stdout', /"baseDir":".*?custom-framework-app"/)
.expect('stdout', /"framework":".*?yadan"/)
.expect('code', 0)
.end(done);
.end(done);
});

describe('auto detect available port', () => {
Expand All @@ -124,9 +124,9 @@ describe('test/lib/cmd/dev.test.js', () => {
it('should auto detect available port', done => {
coffee.fork(eggBin, [ 'dev' ], { cwd })
// .debug()
.expect('stderr', /\[egg-bin] server port 7001 is in use, now using port \d+/)
.expect('code', 0)
.end(done);
.expect('stderr', /\[egg-bin] server port 7001 is in use, now using port \d+/)
.expect('code', 0)
.end(done);
});
});

Expand Down
8 changes: 4 additions & 4 deletions test/lib/cmd/test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ describe('test/lib/cmd/test.test.js', () => {
// example: https://github.com/lelandrichardson/enzyme-example-mocha
return coffee.fork(eggBin, [ 'test' ], { cwd: path.join(__dirname, '../../fixtures/enzyme-example-mocha') })
// .debug()
.expect('stdout', /before hook: delay 10ms/)
.expect('stdout', /3 passing/)
.expect('code', 0)
.end();
.expect('stdout', /before hook: delay 10ms/)
.expect('stdout', /3 passing/)
.expect('code', 0)
.end();
});

describe('simplify mocha error stack', () => {
Expand Down

0 comments on commit 3a9965b

Please sign in to comment.