Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support cov command in win32 #52

Merged
merged 4 commits into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ coverage/
.tmp
.vscode
*.log
package-lock.json
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ Using [istanbul] to run code coverage, it support all test params above.

Coverage reporter will output text-summary, json and lcov.

**NOTE: `cov` is replaced with `test` at win32 system.**

#### options

You can pass any mocha argv.
Expand Down
6 changes: 0 additions & 6 deletions lib/cmd/cov.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ class CovCommand extends Command {
}

* run(context) {
/* istanbul ignore if */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

windows 就是支持 cov 的?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本来就支持,主要是 win 和 unix 路径斜杠不一致的问题

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样的话,骨架那边的 ci 配置是不是要改下默认值,怕 appveyor 跑太慢了。

command: { "travis": "ci", "appveyor": "test" }

https://github.com/eggjs/egg-ci

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这改动对现有的没影响啊~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你这个合并后,所有的插件的 appveyor 都会执行 cov,会慢吧。不过跟这个 PR 关系不大,可以后面单独改。

if (process.platform === 'win32') {
console.warn('`cov` is replaced with `test` at windows');
return yield super.run(context);
}

const { cwd, argv, execArgv } = context;
const tmpDir = path.join(cwd, '.tmp');
yield mkdirp(tmpDir);
Expand Down
253 changes: 117 additions & 136 deletions test/lib/cmd/cov.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,149 +12,130 @@ describe('test/lib/cmd/cov.test.js', () => {

afterEach(mm.restore);

// `cov` is replace with `test` at win32, so we need to skip it
if (process.platform !== 'win32') {
describe('cov at not-win32', () => {
it('should success', done => {
mm(process.env, 'TESTS', 'test/**/*.test.js');
coffee.fork(eggBin, [ 'cov' ], { 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/)
.notExpect('stdout', /a.js/)
.expect('stdout', /Statements {3}: 80% \( 4\/5 \)/)
.expect('code', 0)
.end(err => {
assert.ifError(err);
assert.ok(fs.existsSync(path.join(cwd, 'coverage/coverage-final.json')));
assert.ok(fs.existsSync(path.join(cwd, 'coverage/lcov-report/index.html')));
assert.ok(fs.existsSync(path.join(cwd, 'coverage/lcov.info')));
assert.ok(!fs.existsSync(path.join(cwd, '.tmp')));
done();
});
it('should success', done => {
mm(process.env, 'TESTS', 'test/**/*.test.js');
coffee.fork(eggBin, [ 'cov' ], { 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/)
.notExpect('stdout', /a.js/)
.expect('stdout', /Statements {3}: 80% \( 4[\/|\\]5 \)/)
.expect('code', 0)
.end(err => {
assert.ifError(err);
assert.ok(fs.existsSync(path.join(cwd, 'coverage/coverage-final.json')));
assert.ok(fs.existsSync(path.join(cwd, 'coverage/lcov-report/index.html')));
assert.ok(fs.existsSync(path.join(cwd, 'coverage/lcov.info')));
assert.ok(!fs.existsSync(path.join(cwd, '.tmp')));
done();
});
});

it('should success with COV_EXCLUDES', function* () {
mm(process.env, 'TESTS', 'test/**/*.test.js');
mm(process.env, 'COV_EXCLUDES', 'ignore/*');
yield coffee.fork(eggBin, [ 'cov' ], { 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/)
.notExpect('stdout', /a.js/)
.expect('stdout', /Statements {3}: 75% \( 3\/4 \)/)
.expect('code', 0)
.end();
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 success with COV_EXCLUDES', function* () {
mm(process.env, 'TESTS', 'test/**/*.test.js');
mm(process.env, 'COV_EXCLUDES', 'ignore/*');
yield coffee.fork(eggBin, [ 'cov' ], { 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/)
.notExpect('stdout', /a.js/)
.expect('stdout', /Statements {3}: 75% \( 3[\/|\\]4 \)/)
.expect('code', 0)
.end();
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 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/)
.notExpect('stdout', /a.js/)
.expect('stdout', /Statements {3}: 75% \( 3\/4 \)/)
.expect('code', 0)
.end();
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 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/)
.notExpect('stdout', /a.js/)
.expect('stdout', /Statements {3}: 75% \( 3[\/|\\]4 \)/)
.expect('code', 0)
.end();
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/)
.expect('code', 1)
.end(done);
});
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/)
.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' ], { cwd })
.coverage(false)
// .debug()
.expect('stdout', /1\) should fail/)
.expect('stdout', /1 failing/)
.expect('stdout', /assert\(1 === 2\)/)
.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' ], { cwd })
.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 })
.coverage(false)
// .debug()
.expect('stderr', /manually require `intelli-espower-loader`/)
.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 })
.coverage(false)
// .debug()
.expect('stderr', /manually require `intelli-espower-loader`/)
.expect('stdout', /1\) should fail/)
.expect('stdout', /1 failing/)
.expect('stdout', /assert\(1 === 2\)/)
.expect('code', 1)
.end(done);
});

it('should set EGG_BIN_PREREQUIRE', function* () {
const cwd = path.join(__dirname, '../../fixtures/prerequire');
yield coffee.fork(eggBin, [ 'cov' ], { cwd })
.debug()
.coverage(false)
.expect('stdout', /EGG_BIN_PREREQUIRE undefined/)
.expect('code', 0)
.end();
it('should set EGG_BIN_PREREQUIRE', function* () {
const cwd = path.join(__dirname, '../../fixtures/prerequire');
yield coffee.fork(eggBin, [ 'cov' ], { cwd })
.debug()
.coverage(false)
.expect('stdout', /EGG_BIN_PREREQUIRE undefined/)
.expect('code', 0)
.end();

yield coffee.fork(eggBin, [ 'cov', '--prerequire' ], { cwd })
.debug()
.coverage(false)
.expect('stdout', /EGG_BIN_PREREQUIRE true/)
.expect('code', 0)
.end();
});
yield coffee.fork(eggBin, [ 'cov', '--prerequire' ], { cwd })
.debug()
.coverage(false)
.expect('stdout', /EGG_BIN_PREREQUIRE true/)
.expect('code', 0)
.end();
});

it('should run cov when no test files', function* () {
mm(process.env, 'TESTS', 'noexist.js');
const cwd = path.join(__dirname, '../../fixtures/prerequire');
yield coffee.fork(eggBin, [ 'cov' ], { cwd })
// .debug()
.coverage(false)
.expect('code', 0)
.end();
});
});
} else {
it('should exec test instead of cov in win32', done => {
mm(process, 'platform', 'win32');
mm(process.env, 'TESTS', 'test/**/*.test.js');
coffee.fork(eggBin, [ 'cov' ], { cwd })
.debug()
.expect('stdout', /should success/)
.expect('stdout', /a\.test\.js/)
.expect('stdout', /b\/b\.test\.js/)
.notExpect('stdout', /Coverage summary/)
.notExpect('stdout', /a\.js/)
.expect('code', 0)
.end(done);
});
}
it('should run cov when no test files', function* () {
mm(process.env, 'TESTS', 'noexist.js');
const cwd = path.join(__dirname, '../../fixtures/prerequire');
yield coffee.fork(eggBin, [ 'cov' ], { cwd })
// .debug()
.coverage(false)
.expect('code', 0)
.end();
});
});