Skip to content

Commit

Permalink
feat: build-in intelli-espower-loader (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 authored and fengmk2 committed Dec 14, 2016
1 parent 8bf9aa0 commit 4e86a67
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 15 deletions.
12 changes: 9 additions & 3 deletions .autod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
],
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
7 changes: 7 additions & 0 deletions lib/cov_command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 8 additions & 0 deletions lib/test_command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -39,8 +39,8 @@
"author": "fengmk2 <fengmk2@gmail.com> (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"
},
Expand Down
15 changes: 15 additions & 0 deletions test/egg-cov.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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\)/)
Expand Down
2 changes: 1 addition & 1 deletion test/egg-dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
13 changes: 13 additions & 0 deletions test/egg-test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down

0 comments on commit 4e86a67

Please sign in to comment.