mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-18 00:27:17 +00:00
refactor: wire up coverage
This commit is contained in:
parent
230fe592a6
commit
1456ec60b7
@ -76,6 +76,7 @@ class MochaTestRunner {
|
||||
acctCb(err, accounts);
|
||||
}
|
||||
|
||||
events.emit('tests:ready', accounts);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -103,7 +104,13 @@ class MochaTestRunner {
|
||||
events.request("contracts:reset", next);
|
||||
},
|
||||
(next) => { // get contract files
|
||||
events.request("config:contractsFiles", next);
|
||||
if (!options.coverage) {
|
||||
return events.request("config:contractsFiles", next);
|
||||
}
|
||||
|
||||
events.request("coverage:prepareContracts", () => {
|
||||
events.request("config:contractsFiles", next);
|
||||
});
|
||||
},
|
||||
(cf, next) => { // compile contracts
|
||||
events.request("compiler:contracts:compile", cf, next);
|
||||
@ -149,12 +156,14 @@ class MochaTestRunner {
|
||||
}
|
||||
|
||||
mocha.run((failures) => {
|
||||
next(null, failures);
|
||||
next();
|
||||
});
|
||||
}
|
||||
], (err, failures) => {
|
||||
], (err) => {
|
||||
events.emit('tests:finished');
|
||||
|
||||
Module.prototype.require = originalRequire;
|
||||
cb(err, failures);
|
||||
cb(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,7 @@
|
||||
"embark-i18n": "^4.1.1",
|
||||
"embark-utils": "^4.1.1",
|
||||
"fs-extra": "7.0.1",
|
||||
"istanbul": "0.4.5",
|
||||
"mocha": "6.2.0",
|
||||
"open": "6.4.0"
|
||||
},
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { __ } from 'embark-i18n';
|
||||
const async = require('async');
|
||||
const chalk = require('chalk');
|
||||
const path = require('path');
|
||||
const { embarkPath, dappPath, runCmd } = require('embark-utils');
|
||||
import fs from 'fs';
|
||||
import { COVERAGE_GAS_LIMIT, GAS_LIMIT } from './constants';
|
||||
|
||||
@ -60,10 +62,32 @@ class TestRunner {
|
||||
});
|
||||
|
||||
async.series(runnerFns, next);
|
||||
}
|
||||
},
|
||||
(_results, next) => {
|
||||
if (!options.coverage) {
|
||||
return next();
|
||||
}
|
||||
|
||||
const cmd = `${embarkPath('node_modules/.bin/istanbul')} report --root .embark --format html --format lcov`;
|
||||
runCmd(cmd, {silent: false, exitOnError: false}, next);
|
||||
},
|
||||
], (err) => {
|
||||
reporter.footer();
|
||||
cb(err, reporter.passes, reporter.fails);
|
||||
|
||||
if (!options.coverage) {
|
||||
return cb(err, reporter.passes, reporter.fails);
|
||||
}
|
||||
|
||||
process.stdout.write(chalk`{blue Coverage report created. You can find it here:}\n{white.underline ${dappPath('coverage/index.html')}}\n`);
|
||||
|
||||
if (options.noBrowser) {
|
||||
return cb(err, reporter.passes, reporter.fails);
|
||||
}
|
||||
|
||||
const open = require('open');
|
||||
open(dappPath('coverage/index.html')).then(() => {
|
||||
cb(err, reporter.passes, reporter.fails);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -36,9 +36,9 @@ class Reporter {
|
||||
footer() {
|
||||
const total = this.passes + this.fails;
|
||||
if (this.fails > 0) {
|
||||
process.stdout.write(`>>> Failed ${this.fails} / ${total} test(s).\n`);
|
||||
process.stdout.write(chalk`{red Failed ${this.fails} / ${total} test(s).}\n`);
|
||||
} else {
|
||||
process.stdout.write(`>>> Passed ${this.passes} test(s).\n`);
|
||||
process.stdout.write(chalk`{green Passed ${this.passes} test(s).}\n`);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -190,6 +190,7 @@ class Engine {
|
||||
|
||||
testComponents() {
|
||||
this.registerModulePackage('embark-test-runner');
|
||||
this.registerModulePackage('embark-coverage');
|
||||
this.registerModulePackage('embark-solidity-tests');
|
||||
this.registerModulePackage('embark-mocha-tests');
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user