diff --git a/.travis.yml b/.travis.yml index 03736ab2..86060430 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ node_js: - '4' - '6' install: - - npm i npminstall && npminstall + - npm i npminstall@beta && npminstall script: - npm run ci after_script: diff --git a/appveyor.yml b/appveyor.yml index e4893768..b1f1cf32 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,7 +5,7 @@ environment: install: - ps: Install-Product node $env:nodejs_version - - npm i npminstall && node_modules\.bin\npminstall + - npm i npminstall@beta && node_modules\.bin\npminstall test_script: - node --version diff --git a/lib/cov_command.js b/lib/cov_command.js index 0d54c474..663abbb0 100644 --- a/lib/cov_command.js +++ b/lib/cov_command.js @@ -15,7 +15,7 @@ class CovCommand extends Command { ]; } - * run(cwd) { + * run(cwd, args) { process.env.NODE_ENV = 'test'; process.env.TMPDIR = path.join(cwd, '.tmp'); mkdirp.sync(process.env.TMPDIR); @@ -30,7 +30,7 @@ class CovCommand extends Command { rimraf.sync(coverageDir); // save coverage-xxxx.json to $PWD/coverage - const covArgs = this.getCovArgs(); + const covArgs = this.getCovArgs(args); yield this.helper.forkNode(covFile, covArgs, opt); rimraf.sync(process.env.TMPDIR); @@ -47,7 +47,7 @@ class CovCommand extends Command { this.excludes.push(exclude); } - getCovArgs() { + getCovArgs(args) { let covArgs = [ 'cover', '--report', 'none', @@ -63,7 +63,7 @@ class CovCommand extends Command { '--', '--timeout', process.env.TEST_TIMEOUT || '200000', '--require', require.resolve('thunk-mocha'), - ]).concat(this.helper.getTestFiles()); + ]).concat(this.helper.getTestFiles()).concat(args); return covArgs; } diff --git a/lib/test_command.js b/lib/test_command.js index eec3977b..f9fd1bfc 100644 --- a/lib/test_command.js +++ b/lib/test_command.js @@ -1,17 +1,16 @@ 'use strict'; const mochaFile = require.resolve('mocha/bin/_mocha'); -const thunkMocha = require.resolve('thunk-mocha'); const Command = require('./command'); class TestCommand extends Command { - * run() { - const args = [ + * run(_, args) { + args = [ mochaFile, '--reporter', process.env.TEST_REPORTER || 'spec', '--timeout', process.env.TEST_TIMEOUT || '30000', - '--require', thunkMocha, - ].concat(this.helper.getTestFiles()); + '--require', require.resolve('thunk-mocha'), + ].concat(this.helper.getTestFiles()).concat(args); process.env.NODE_ENV = 'test'; const opt = { diff --git a/package.json b/package.json index 44c8e44a..0309ae97 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,9 @@ "egg-ci": "1", "eslint": "3", "eslint-config-egg": "3", - "mm": "1" + "intelli-espower-loader": "^1.0.1", + "mm": "1", + "power-assert": "^1.4.1" }, "repository": { "type": "git", @@ -37,8 +39,8 @@ "author": "fengmk2 (https://fengmk2.com)", "scripts": { "lint": "eslint --fix bin lib test *.js", - "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", + "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", "ci": "npm run lint && npm run cov", "autod": "autod -e test/fixtures -f '^' -w" }, diff --git a/test/egg-cov.test.js b/test/egg-cov.test.js index c3c252c2..c38eb50c 100644 --- a/test/egg-cov.test.js +++ b/test/egg-cov.test.js @@ -2,7 +2,7 @@ const fs = require('fs'); const path = require('path'); -const assert = require('assert'); +const assert = require('power-assert'); const coffee = require('coffee'); const mm = require('mm'); @@ -51,4 +51,18 @@ describe('egg-bin cov', () => { .expect('code', 1) .end(done); }); + + it('should fail when test fail with power-assert', done => { + mm(process.env, 'TESTS', 'test/power-assert-fail.js'); + coffee.fork(eggBin, [ 'cov', '-r', 'intelli-espower-loader' ], { + cwd: appdir, + }) + .coverage(false) + // .debug() + .expect('stdout', /1\) should fail/) + .expect('stdout', /1 failing/) + .expect('stdout', /assert\(1 === 2\)/) + .expect('code', 1) + .end(done); + }); }); diff --git a/test/egg-test.test.js b/test/egg-test.test.js index 570e5733..d8d2f352 100644 --- a/test/egg-test.test.js +++ b/test/egg-test.test.js @@ -1,36 +1,33 @@ 'use strict'; const path = require('path'); -const assert = require('assert'); +const assert = require('power-assert'); const coffee = require('coffee'); const mm = require('mm'); describe('egg-bin test', () => { const eggBin = require.resolve('../bin/egg-bin.js'); + const cwd = path.join(__dirname, 'fixtures/test-files'); afterEach(mm.restore); it('should success', done => { mm(process.env, 'TESTS', 'test/**/*.test.js'); - coffee.fork(eggBin, [ 'test' ], { - cwd: path.join(__dirname, 'fixtures/test-files'), - }) + coffee.fork(eggBin, [ 'test' ], { cwd }) .expect('stdout', /✓ should success/) .expect('stdout', /a\.test\.js/) .expect('stdout', /b\/b\.test\.js/) .expect('code', 0) .end((err, res) => { assert.ifError(err); - assert.ok(!/a.js/.test(res.stdout)); + assert.ok(!/a\.js/.test(res.stdout)); done(); }); }); it('should only test files specified by TESTS', done => { mm(process.env, 'TESTS', 'test/a.test.js'); - coffee.fork(eggBin, [ 'test' ], { - cwd: path.join(__dirname, 'fixtures/test-files'), - }) + coffee.fork(eggBin, [ 'test' ], { cwd }) .expect('stdout', /✓ should success/) .expect('stdout', /a\.test\.js/) .expect('code', 0) @@ -44,9 +41,7 @@ describe('egg-bin test', () => { it('should use process.env.TEST_REPORTER', done => { mm(process.env, 'TESTS', 'test/**/*.test.js'); mm(process.env, 'TEST_REPORTER', 'dot'); - coffee.fork(eggBin, [ 'test' ], { - cwd: path.join(__dirname, 'fixtures/test-files'), - }) + coffee.fork(eggBin, [ 'test' ], { cwd }) .expect('stdout', /․․\n/) .expect('code', 0) .end((err, res) => { @@ -59,14 +54,24 @@ describe('egg-bin test', () => { it('should use process.env.TEST_TIMEOUT', done => { mm(process.env, 'TESTS', 'test/**/*.test.js'); mm(process.env, 'TEST_TIMEOUT', '60000'); - coffee.fork(eggBin, [ 'test' ], { - cwd: path.join(__dirname, 'fixtures/test-files'), - }) + coffee.fork(eggBin, [ 'test' ], { cwd }) .expect('stdout', /✓ should success/) .expect('code', 0) .end(done); }); + it('should fail when test fail with power-assert', done => { + mm(process.env, 'TESTS', 'test/power-assert-fail.js'); + coffee.fork(eggBin, [ 'cov', '-r', 'intelli-espower-loader' ], { cwd }) + .coverage(false) + // .debug() + .expect('stdout', /1\) should fail/) + .expect('stdout', /assert\(1 === 2\)/) + .expect('stdout', /1 failing/) + .expect('code', 1) + .end(done); + }); + it.skip('should check node dependencies fail', done => { coffee.fork(eggBin, [ 'test' ], { cwd: path.join(__dirname, 'fixtures/check-deps-fail'), diff --git a/test/fixtures/test-files/test/power-assert-fail.js b/test/fixtures/test-files/test/power-assert-fail.js new file mode 100644 index 00000000..6dfccb32 --- /dev/null +++ b/test/fixtures/test-files/test/power-assert-fail.js @@ -0,0 +1,9 @@ +'use strict'; + +const assert = require('power-assert'); + +describe('power-assert-fail.js', () => { + it('should fail', () => { + assert(1 === 2); + }); +}); diff --git a/test/my-egg-bin.test.js b/test/my-egg-bin.test.js index 29beec1a..4b835f15 100644 --- a/test/my-egg-bin.test.js +++ b/test/my-egg-bin.test.js @@ -1,7 +1,7 @@ 'use strict'; const path = require('path'); -const assert = require('assert'); +const assert = require('power-assert'); const coffee = require('coffee'); const mm = require('mm');