mirror of https://gitee.com/bigwinds/arangodb
Extract util.indentation
This commit is contained in:
parent
c919cb7be8
commit
c18aa323dc
|
@ -29,8 +29,10 @@
|
||||||
// //////////////////////////////////////////////////////////////////////////////
|
// //////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
const Module = require('module');
|
const Module = require('module');
|
||||||
|
const Chalk = require('chalk').constructor;
|
||||||
|
const chalk = new Chalk({enabled: true});
|
||||||
const runTests = require('@arangodb/mocha').run;
|
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');
|
const $_MODULE_CONTEXT = Symbol.for('@arangodb/module.context');
|
||||||
|
|
||||||
|
@ -47,42 +49,21 @@ module.exports = function (files, returnJson, grep) {
|
||||||
};
|
};
|
||||||
|
|
||||||
function logStats (stats) {
|
function logStats (stats) {
|
||||||
print(
|
print(`${
|
||||||
(
|
|
||||||
stats.failures
|
stats.failures
|
||||||
? (
|
? chalk.red('[FAIL]')
|
||||||
colors.COLOR_RED
|
: chalk.green('[PASS]')
|
||||||
+ '[FAIL]'
|
} Completed ${
|
||||||
+ colors.COLOR_RESET
|
chalk.bold(stats.tests)
|
||||||
)
|
} tests in ${
|
||||||
: (
|
chalk.bold(stats.duration + 'ms')
|
||||||
colors.COLOR_GREEN
|
} (${
|
||||||
+ '[PASS]'
|
chalk.green(stats.passes)
|
||||||
+ colors.COLOR_RESET
|
} | ${
|
||||||
)
|
chalk.red(stats.failures)
|
||||||
)
|
} | ${
|
||||||
+ ' Completed '
|
chalk.cyan(stats.pending)
|
||||||
+ 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
|
|
||||||
+ ' )'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function logSuite (suite, indentLevel) {
|
function logSuite (suite, indentLevel) {
|
||||||
|
@ -91,43 +72,30 @@ function logSuite (suite, indentLevel) {
|
||||||
}
|
}
|
||||||
if (suite.title) {
|
if (suite.title) {
|
||||||
print(
|
print(
|
||||||
indent(indentLevel - 1)
|
indent(indentLevel - 1) +
|
||||||
+ colors.COLOR_BOLD_WHITE
|
chalk.bold(suite.title)
|
||||||
+ suite.title
|
|
||||||
+ colors.COLOR_RESET
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for (let test of suite.tests) {
|
for (let test of suite.tests) {
|
||||||
if (test.result === 'pass') {
|
if (test.result === 'pass') {
|
||||||
print(
|
print(
|
||||||
indent(indentLevel)
|
indent(indentLevel) +
|
||||||
+ colors.COLOR_GREEN
|
chalk.green('[PASS] ' + test.title)
|
||||||
+ '[PASS] '
|
|
||||||
+ test.title
|
|
||||||
+ colors.COLOR_RESET
|
|
||||||
);
|
);
|
||||||
} else if (test.result === 'pending') {
|
} else if (test.result === 'pending') {
|
||||||
print(
|
print(
|
||||||
indent(indentLevel)
|
indent(indentLevel) +
|
||||||
+ colors.COLOR_CYAN
|
chalk.cyan('[SKIP] ' + test.title)
|
||||||
+ '[SKIP] '
|
|
||||||
+ test.title
|
|
||||||
+ colors.COLOR_RESET
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
print(
|
print(
|
||||||
indent(indentLevel)
|
indent(indentLevel) +
|
||||||
+ colors.COLOR_RED
|
chalk.red('[' + test.result.toUpperCase() + '] ' + test.title)
|
||||||
+ '[' + test.result.toUpperCase() + '] '
|
|
||||||
+ test.title
|
|
||||||
+ colors.COLOR_RESET
|
|
||||||
);
|
);
|
||||||
for (let line of test.err.stack.split(/\n/)) {
|
for (let line of test.err.stack.split(/\n/)) {
|
||||||
print(
|
print(
|
||||||
indent(indentLevel + 1)
|
indent(indentLevel + 1) +
|
||||||
+ colors.COLOR_RED
|
chalk.red(line)
|
||||||
+ line
|
|
||||||
+ colors.COLOR_RESET
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
function buildJson (results) {
|
||||||
const result = {
|
const result = {
|
||||||
duration: results.stats.duration,
|
duration: results.stats.duration,
|
||||||
status: results.stats.failures ? false : true,
|
status: !results.stats.failures,
|
||||||
failed: results.stats.failures,
|
failed: results.stats.failures,
|
||||||
total: results.stats.tests
|
total: results.stats.tests
|
||||||
};
|
};
|
||||||
|
|
|
@ -175,3 +175,14 @@ exports.shallowCopy = function (src) {
|
||||||
}
|
}
|
||||||
return dest;
|
return dest;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.indentation = function (level, indentWith) {
|
||||||
|
if (!indentWith) {
|
||||||
|
indentWith = ' ';
|
||||||
|
}
|
||||||
|
let padding = '';
|
||||||
|
for (let i = 0; i < level; i++) {
|
||||||
|
padding += indentWith;
|
||||||
|
}
|
||||||
|
return padding;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue