Merge pull request #518 from embark-framework/bug_fix/test-should-log

Enable loglevel for test logger and actually log
This commit is contained in:
Iuri Matias 2018-06-13 11:36:00 -04:00 committed by GitHub
commit a69d3f7ba1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 17 deletions

View File

@ -185,10 +185,11 @@ class Cmd {
program program
.command('test [file]') .command('test [file]')
.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')
.description(__('run tests')) .description(__('run tests'))
.action(function (file, options) { .action(function (file, options) {
i18n.setOrDetectLocale(options.locale); i18n.setOrDetectLocale(options.locale);
embark.runTests(file); embark.runTests({file, loglevel: options.loglevel});
}); });
} }

View File

@ -362,10 +362,10 @@ class Embark {
}); });
} }
runTests(file) { runTests(options) {
this.context = [constants.contexts.test]; this.context = [constants.contexts.test];
let RunTests = require('./tests/run_tests.js'); let RunTests = require('./tests/run_tests.js');
RunTests.run(file); RunTests.run(options);
} }
} }

View File

@ -22,9 +22,11 @@ function getFilesFromDir(filePath, cb) {
} }
module.exports = { module.exports = {
run: function (filePath) { run: function (options) {
process.env.isTest = true; process.env.isTest = true;
let failures = 0; let failures = 0;
let filePath = options.file;
const loglevel = options.loglevel || 'warn';
if (!filePath) { if (!filePath) {
filePath = 'test/'; filePath = 'test/';
} }
@ -49,7 +51,7 @@ module.exports = {
}, },
function setupGlobalNamespace(files, next) { function setupGlobalNamespace(files, next) {
// TODO put default config // TODO put default config
const test = new Test(); const test = new Test({loglevel});
global.embark = test; global.embark = test;
global.assert = assert; global.assert = assert;
global.config = test.config.bind(test); global.config = test.config.bind(test);

View File

@ -90,7 +90,7 @@ class Test {
}); });
this.engine.init({ this.engine.init({
logger: new TestLogger({logLevel: 'debug'}) logger: new TestLogger({logLevel: this.options.loglevel})
}); });
this.versions_default = this.engine.config.contractsConfig.versions; this.versions_default = this.engine.config.contractsConfig.versions;

View File

@ -5,21 +5,11 @@ require('colors');
class TestLogger { class TestLogger {
constructor(options) { constructor(options) {
this.logLevels = ['error', 'warn', 'info', 'debug', 'trace']; this.logLevels = ['error', 'warn', 'info', 'debug', 'trace'];
this.logs = [];
this.logLevel = options.logLevel || 'info'; this.logLevel = options.logLevel || 'info';
} }
logFunction() { logFunction() {
this.logs.push(arguments); console.log(...arguments);
// console.log(...arguments);
}
contractsState() {
this.logs.push(arguments);
}
availableServices() {
this.logs.push(arguments);
} }
error(txt) { error(txt) {