1
0
Fork 0

Extract util.indentation

This commit is contained in:
Alan Plum 2017-03-15 19:33:01 +01:00
parent c919cb7be8
commit c18aa323dc
No known key found for this signature in database
GPG Key ID: 8ED72A9A323B6EFD
2 changed files with 39 additions and 71 deletions

View File

@ -29,8 +29,10 @@
// //////////////////////////////////////////////////////////////////////////////
const Module = require('module');
const Chalk = require('chalk').constructor;
const chalk = new Chalk({enabled: true});
const runTests = require('@arangodb/mocha').run;
const colors = require('internal').COLORS;
const indent = require('@arangodb/util').indentation;
const $_MODULE_CONTEXT = Symbol.for('@arangodb/module.context');
@ -47,42 +49,21 @@ module.exports = function (files, returnJson, grep) {
};
function logStats (stats) {
print(
(
print(`${
stats.failures
? (
colors.COLOR_RED
+ '[FAIL]'
+ colors.COLOR_RESET
)
: (
colors.COLOR_GREEN
+ '[PASS]'
+ colors.COLOR_RESET
)
)
+ ' Completed '
+ colors.COLOR_BOLD_WHITE
+ stats.tests
+ colors.COLOR_RESET
+ ' tests in '
+ colors.COLOR_BOLD_WHITE
+ stats.duration + 'ms'
+ colors.COLOR_RESET
+ ' ( '
+ colors.COLOR_GREEN
+ stats.passes
+ colors.COLOR_RESET
+ ' | '
+ colors.COLOR_RED
+ stats.failures
+ colors.COLOR_RESET
+ ' | '
+ colors.COLOR_CYAN
+ stats.pending
+ colors.COLOR_RESET
+ ' )'
);
? chalk.red('[FAIL]')
: chalk.green('[PASS]')
} Completed ${
chalk.bold(stats.tests)
} tests in ${
chalk.bold(stats.duration + 'ms')
} (${
chalk.green(stats.passes)
} | ${
chalk.red(stats.failures)
} | ${
chalk.cyan(stats.pending)
})`);
}
function logSuite (suite, indentLevel) {
@ -91,43 +72,30 @@ function logSuite (suite, indentLevel) {
}
if (suite.title) {
print(
indent(indentLevel - 1)
+ colors.COLOR_BOLD_WHITE
+ suite.title
+ colors.COLOR_RESET
indent(indentLevel - 1) +
chalk.bold(suite.title)
);
}
for (let test of suite.tests) {
if (test.result === 'pass') {
print(
indent(indentLevel)
+ colors.COLOR_GREEN
+ '[PASS] '
+ test.title
+ colors.COLOR_RESET
indent(indentLevel) +
chalk.green('[PASS] ' + test.title)
);
} else if (test.result === 'pending') {
print(
indent(indentLevel)
+ colors.COLOR_CYAN
+ '[SKIP] '
+ test.title
+ colors.COLOR_RESET
indent(indentLevel) +
chalk.cyan('[SKIP] ' + test.title)
);
} else {
print(
indent(indentLevel)
+ colors.COLOR_RED
+ '[' + test.result.toUpperCase() + '] '
+ test.title
+ colors.COLOR_RESET
indent(indentLevel) +
chalk.red('[' + test.result.toUpperCase() + '] ' + test.title)
);
for (let line of test.err.stack.split(/\n/)) {
print(
indent(indentLevel + 1)
+ colors.COLOR_RED
+ line
+ colors.COLOR_RESET
indent(indentLevel + 1) +
chalk.red(line)
);
}
}
@ -140,21 +108,10 @@ function logSuite (suite, indentLevel) {
}
}
function indent (level, indentWith) {
if (!indentWith) {
indentWith = ' ';
}
let padding = '';
for (let i = 0; i < level; i++) {
padding += indentWith;
}
return padding;
}
function buildJson (results) {
const result = {
duration: results.stats.duration,
status: results.stats.failures ? false : true,
status: !results.stats.failures,
failed: results.stats.failures,
total: results.stats.tests
};

View File

@ -175,3 +175,14 @@ exports.shallowCopy = function (src) {
}
return dest;
};
exports.indentation = function (level, indentWith) {
if (!indentWith) {
indentWith = ' ';
}
let padding = '';
for (let i = 0; i < level; i++) {
padding += indentWith;
}
return padding;
};