diff --git a/.autod.conf b/.autod.conf index 67308e20..d9af5a64 100644 --- a/.autod.conf +++ b/.autod.conf @@ -7,13 +7,19 @@ module.exports = { exclude: [ 'test/fixtures', ], + dep: [ + 'istanbul', + 'mocha', + 'thunk-mocha', + 'intelli-espower-loader', + ], devdep: [ 'autod', + 'eslint-config-egg', + 'eslint', + 'egg-ci', ], keep: [ - 'istanbul', - 'mocha', - 'thunk-mocha', ], semver: [ ], diff --git a/README.md b/README.md index 241b16eb..d3131afd 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,8 @@ $ egg-bin debug Using [mocha] with [thunk-mocha] to run test. +[power-assert] is recommend to used as `assert` library, and [intelli-espower-loader] will be auotoload. + You can set `TESTS` env to set the tests directory, it support [glob] grammar. ```bash @@ -194,3 +196,5 @@ run nsp check at /foo/bar with [] [istanbul]: https://github.com/gotwarlost/istanbul [nsp]: https://npmjs.com/thunk-mocha [iron-node]: https://github.com/s-a/iron-node +[intelli-espower-loader]: https://github.com/power-assert-js/intelli-espower-loader +[power-assert]: https://github.com/power-assert-js/power-assert \ No newline at end of file diff --git a/README.zh-CN.md b/README.zh-CN.md index 3d6a7d7f..11a1cf8a 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -72,6 +72,8 @@ $ egg-bin debug 测试工具,使用 [mocha],支持 [thunk-mocha] 扩展。 +内置了 [intelli-espower-loader] 并推荐使用 [power-assert] 作为断言库, 具体参见 https://github.com/atian25/blog/issues/16 + 可通过 `TESTS` 环境变量指定具体文件,支持 [glob]。 ```bash @@ -182,3 +184,5 @@ run nsp check at /foo/bar with [] [glob]: https://github.com/isaacs/node-glob [istanbul]: https://github.com/gotwarlost/istanbul [nsp]: https://npmjs.com/thunk-mocha +[intelli-espower-loader]: https://github.com/power-assert-js/intelli-espower-loader +[power-assert]: https://github.com/power-assert-js/power-assert diff --git a/lib/cov_command.js b/lib/cov_command.js index ea2118f6..34ce27f4 100644 --- a/lib/cov_command.js +++ b/lib/cov_command.js @@ -74,6 +74,13 @@ class CovCommand extends Command { '--require', require.resolve('thunk-mocha'), ]).concat(this.helper.getTestFiles()).concat(args); + if (args.indexOf('intelli-espower-loader') !== -1) { + console.warn('[egg-bin] don\'t need to manually require `intelli-espower-loader` anymore'); + } else { + covArgs.push('--require'); + covArgs.push(require.resolve('intelli-espower-loader')); + } + return covArgs; } diff --git a/lib/test_command.js b/lib/test_command.js index f9fd1bfc..02fc2b63 100644 --- a/lib/test_command.js +++ b/lib/test_command.js @@ -11,6 +11,14 @@ class TestCommand extends Command { '--timeout', process.env.TEST_TIMEOUT || '30000', '--require', require.resolve('thunk-mocha'), ].concat(this.helper.getTestFiles()).concat(args); + + if (args.indexOf('intelli-espower-loader') !== -1) { + console.warn('[egg-bin] don\'t need to manually require `intelli-espower-loader` anymore'); + } else { + args.push('--require'); + args.push(require.resolve('intelli-espower-loader')); + } + process.env.NODE_ENV = 'test'; const opt = { diff --git a/package.json b/package.json index 5e8071b2..1abfc9c3 100644 --- a/package.json +++ b/package.json @@ -11,25 +11,25 @@ "childprocess": "^2.0.2", "commander": "^2.9.0", "common-bin": "^1.0.0", - "debug": "^2.2.0", + "debug": "^2.3.3", "egg-utils": "^1.0.0", "glob": "^7.1.1", - "istanbul": "^0.4.0", + "intelli-espower-loader": "^1.0.1", + "istanbul": "^0.4.5", "mkdirp": "^0.5.1", - "mocha": "^3.0.0", + "mocha": "^3.2.0", "rimraf": "^2.5.4", "semver": "^5.3.0", - "thunk-mocha": "^1.0.3" + "thunk-mocha": "^1.0.8" }, "devDependencies": { "autod": "^2.7.1", "coffee": "^3.3.0", - "egg-ci": "1", - "eslint": "3", - "eslint-config-egg": "3", - "intelli-espower-loader": "^1.0.1", + "egg-ci": "^1.1.0", + "eslint": "^3.12.1", + "eslint-config-egg": "^3.2.0", "mm": "^2.0.0", - "power-assert": "^1.4.1" + "power-assert": "^1.4.2" }, "repository": { "type": "git", @@ -39,8 +39,8 @@ "author": "fengmk2 (https://fengmk2.com)", "scripts": { "lint": "eslint bin lib test *.js", - "test": "TEST_TIMEOUT=3600000 TESTS=test/*.test.js bin/egg-bin.js test -r intelli-espower-loader", - "cov": "TEST_TIMEOUT=3600000 TESTS=test/*.test.js bin/egg-bin.js cov -r intelli-espower-loader", + "test": "TEST_TIMEOUT=3600000 TESTS=test/*.test.js bin/egg-bin.js test", + "cov": "TEST_TIMEOUT=3600000 TESTS=test/*.test.js bin/egg-bin.js cov", "ci": "npm run lint && npm run cov", "autod": "autod" }, diff --git a/test/egg-cov.test.js b/test/egg-cov.test.js index c71909d2..4e0a4387 100644 --- a/test/egg-cov.test.js +++ b/test/egg-cov.test.js @@ -75,12 +75,27 @@ describe('egg-bin cov', () => { }); it('should fail when test fail with power-assert', done => { + mm(process.env, 'TESTS', 'test/power-assert-fail.js'); + coffee.fork(eggBin, [ 'cov' ], { + cwd: appdir, + }) + .coverage(false) + // .debug() + .expect('stdout', /1\) should fail/) + .expect('stdout', /1 failing/) + .expect('stdout', /assert\(1 === 2\)/) + .expect('code', 1) + .end(done); + }); + + 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: appdir, }) .coverage(false) // .debug() + .expect('stderr', /manually require `intelli-espower-loader`/) .expect('stdout', /1\) should fail/) .expect('stdout', /1 failing/) .expect('stdout', /assert\(1 === 2\)/) diff --git a/test/egg-dev.test.js b/test/egg-dev.test.js index 671f6e21..47173435 100644 --- a/test/egg-dev.test.js +++ b/test/egg-dev.test.js @@ -27,7 +27,7 @@ describe('egg-bin dev', () => { .end(done); }); - it('should startCluster with execArgv --debug', done => { + it.skip('should startCluster with execArgv --debug', done => { coffee.fork(eggBin, [ 'dev', '--debug=7000' ], { cwd: appdir, }) diff --git a/test/egg-test.test.js b/test/egg-test.test.js index d8d2f352..21e24fdf 100644 --- a/test/egg-test.test.js +++ b/test/egg-test.test.js @@ -61,10 +61,23 @@ describe('egg-bin test', () => { }); 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', /assert\(1 === 2\)/) + .expect('stdout', /1 failing/) + .expect('code', 1) + .end(done); + }); + + 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/) .expect('stdout', /assert\(1 === 2\)/) .expect('stdout', /1 failing/)