Merge pull request #828 from embark-framework/features/coverage-option
Add --coverage option to tests
This commit is contained in:
commit
45d6d4358e
|
@ -266,13 +266,15 @@ class Cmd {
|
||||||
.command('test [file]')
|
.command('test [file]')
|
||||||
.option('-n , --node [node]', __('Node to connect to (default: vm)'))
|
.option('-n , --node [node]', __('Node to connect to (default: vm)'))
|
||||||
.option('-d , --gasDetails', __('When set, will print the gas cost for each contract deploy'))
|
.option('-d , --gasDetails', __('When set, will print the gas cost for each contract deploy'))
|
||||||
|
.option('-c , --coverage', __('When set, will generate the coverage after the tests'))
|
||||||
.option('--locale [locale]', __('language to use (default: en)'))
|
.option('--locale [locale]', __('language to use (default: en)'))
|
||||||
.option('--loglevel [loglevel]', __('level of logging to display') + ' ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'warn')
|
.option('--loglevel [loglevel]', __('level of logging to display') + ' ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'warn')
|
||||||
.description(__('run tests'))
|
.description(__('run tests'))
|
||||||
.action(function(file, options) {
|
.action(function(file, options) {
|
||||||
checkDeps();
|
checkDeps();
|
||||||
i18n.setOrDetectLocale(options.locale);
|
i18n.setOrDetectLocale(options.locale);
|
||||||
embark.runTests({file, loglevel: options.loglevel, gasDetails: options.gasDetails, node: options.node});
|
embark.runTests({file, loglevel: options.loglevel, gasDetails: options.gasDetails,
|
||||||
|
node: options.node, coverage: options.coverage});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,18 @@ function mkdirp() {
|
||||||
return fs.mkdirp.apply(fs.mkdirp, arguments);
|
return fs.mkdirp.apply(fs.mkdirp, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readdir() {
|
||||||
|
return fs.readdir.apply(fs.readdir, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
function stat() {
|
||||||
|
return fs.stat.apply(fs.stat, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove() {
|
||||||
|
return fs.remove.apply(fs.remove, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
function copy() {
|
function copy() {
|
||||||
return fs.copy.apply(fs.copy, arguments);
|
return fs.copy.apply(fs.copy, arguments);
|
||||||
}
|
}
|
||||||
|
@ -106,6 +118,9 @@ function tmpDir() {
|
||||||
module.exports = {
|
module.exports = {
|
||||||
mkdirpSync,
|
mkdirpSync,
|
||||||
mkdirp,
|
mkdirp,
|
||||||
|
readdir,
|
||||||
|
stat,
|
||||||
|
remove,
|
||||||
copy,
|
copy,
|
||||||
copySync,
|
copySync,
|
||||||
move,
|
move,
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const fs = require('fs-extra');
|
|
||||||
const Mocha = require('mocha');
|
const Mocha = require('mocha');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const {runCmd} = require('../utils/utils');
|
||||||
|
const fs = require('../core/fs');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const Test = require('./test');
|
const Test = require('./test');
|
||||||
const EmbarkSpec = require('./reporter');
|
const EmbarkSpec = require('./reporter');
|
||||||
|
@ -123,6 +124,24 @@ module.exports = {
|
||||||
eachCb();
|
eachCb();
|
||||||
});
|
});
|
||||||
}, next);
|
}, next);
|
||||||
|
},
|
||||||
|
function runCoverage(next) {
|
||||||
|
if (!options.coverage) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
runCmd(`${fs.embarkPath('node_modules/.bin/istanbul')} report --root .embark --format html`,
|
||||||
|
{silent: false, exitOnError: false}, (err) => {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
console.log(`Coverage report created. You can find it here: ${fs.dappPath('coverage/index.html')}\n`);
|
||||||
|
const opn = require('opn');
|
||||||
|
const _next = () => { next(); };
|
||||||
|
opn(fs.dappPath('coverage/index.html'), {wait: false})
|
||||||
|
.then(() => new Promise(resolve => setTimeout(resolve, 1000)))
|
||||||
|
.then(_next, _next);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
], (err) => {
|
], (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -58,6 +58,7 @@
|
||||||
"i18n": "^0.8.3",
|
"i18n": "^0.8.3",
|
||||||
"ipfs-api": "17.2.4",
|
"ipfs-api": "17.2.4",
|
||||||
"is-valid-domain": "0.0.5",
|
"is-valid-domain": "0.0.5",
|
||||||
|
"istanbul": "^0.4.5",
|
||||||
"live-plugin-manager-git-fix": "^0.12.1",
|
"live-plugin-manager-git-fix": "^0.12.1",
|
||||||
"lodash.clonedeep": "^4.5.0",
|
"lodash.clonedeep": "^4.5.0",
|
||||||
"merge": "^1.2.0",
|
"merge": "^1.2.0",
|
||||||
|
|
Loading…
Reference in New Issue