test(@embark/stack/test-runner): enable test-runner's test suite

Introduce some light refactoring related to embark-testing facilities, and also
a configurable stdout option so the output of the reporter implemented in this
package isn't confusingly mixed into unit test reporting for this package.
This commit is contained in:
Michael Bradley, Jr 2019-10-25 11:01:56 -05:00 committed by Michael Bradley
parent 0af6e13779
commit a4ee9f8739
4 changed files with 15 additions and 9 deletions

View File

@ -33,7 +33,7 @@
"ci": "npm run qa", "ci": "npm run qa",
"clean": "npm run reset", "clean": "npm run reset",
"lint": "eslint src/", "lint": "eslint src/",
"qa": "npm-run-all lint _build", "qa": "npm-run-all lint _build test",
"reset": "npx rimraf .nyc_output dist embark-*.tgz package", "reset": "npx rimraf .nyc_output dist embark-*.tgz package",
"solo": "embark-solo", "solo": "embark-solo",
"test": "nyc --reporter=html --reporter=json mocha \"dist/test/**/*.js\" --exit --no-timeouts --require source-map-support/register" "test": "nyc --reporter=html --reporter=json mocha \"dist/test/**/*.js\" --exit --no-timeouts --require source-map-support/register"

View File

@ -22,6 +22,7 @@ class TestRunner {
this.logger = embark.logger; this.logger = embark.logger;
this.events = embark.events; this.events = embark.events;
this.plugins = options.plugins; this.plugins = options.plugins;
this.stdout = options.stdout || process.stdout;
this.fs = embark.fs; this.fs = embark.fs;
this.runners = []; this.runners = [];
this.files = []; this.files = [];
@ -46,7 +47,7 @@ class TestRunner {
} }
run(options, cb) { run(options, cb) {
const reporter = new Reporter(this.embark); const reporter = new Reporter(this.embark, {stdout: this.stdout});
const testPath = options.file || "test"; const testPath = options.file || "test";
this.setupGlobalVariables(); this.setupGlobalVariables();

View File

@ -1,8 +1,9 @@
const chalk = require('chalk'); const chalk = require('chalk');
class Reporter { class Reporter {
constructor(embark) { constructor(embark, options) {
this.embark = embark; this.embark = embark;
this.stdout = options.stdout || process.stdout;
this.passes = 0; this.passes = 0;
this.fails = 0; this.fails = 0;
@ -36,9 +37,9 @@ class Reporter {
footer() { footer() {
const total = this.passes + this.fails; const total = this.passes + this.fails;
if (this.fails > 0) { if (this.fails > 0) {
process.stdout.write(chalk`{red Failed ${this.fails} / ${total} test(s).}\n`); this.stdout.write(chalk`{red Failed ${this.fails} / ${total} test(s).}\n`);
} else { } else {
process.stdout.write(chalk`{green Passed ${this.passes} test(s).}\n`); this.stdout.write(chalk`{green Passed ${this.passes} test(s).}\n`);
} }
} }
@ -55,10 +56,10 @@ class Reporter {
if (passed) { if (passed) {
this.passes++; this.passes++;
process.stdout.write(chalk`{bgGreen.white.bold ${' PASS '}} {underline ${test}} {bold >} {${timeFormat} ${time}s} {bold >} {bold ${formattedGas} gas}\n`); this.stdout.write(chalk`{bgGreen.white.bold ${' PASS '}} {underline ${test}} {bold >} {${timeFormat} ${time}s} {bold >} {bold ${formattedGas} gas}\n`);
} else { } else {
this.fails++; this.fails++;
process.stdout.write(chalk`{bgRed.white.bold ${' FAIL '}} {underline ${test}} {bold >} {${timeFormat} ${time}s} {bold >} {bold ${formattedGas} gas} > {red ${message || 'no error message'}}\n`); this.stdout.write(chalk`{bgRed.white.bold ${' FAIL '}} {underline ${test}} {bold >} {${timeFormat} ${time}s} {bold >} {bold ${formattedGas} gas} > {red ${message || 'no error message'}}\n`);
} }
this.resetGas(); this.resetGas();

View File

@ -11,9 +11,13 @@ describe('Test Runner', () => {
let instance; let instance;
beforeEach(() => { beforeEach(() => {
const { embark } = fakeEmbark(); const { embark } = fakeEmbark({ contractsConfig: {} });
embark.events.setCommandHandler('config:contractsConfig:set', (config, cb) => {
embark.config.contractsConfig = config;
cb(null);
});
_embark = embark; _embark = embark;
instance = new TestRunner(embark, {}); instance = new TestRunner(embark, {stdout: {write: () => {}}});
}); });
describe('command handlers', () => { describe('command handlers', () => {