Skip to content

Commit

Permalink
feat: color trace line path
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Dalecky authored and Vadim Dalecky committed Nov 7, 2017
1 parent fa07fa7 commit e3595c0
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/TapReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const STATUS_PASSED = 'passed';
const STATUS_FAILED = 'failed';
const STATUS_PENDING = 'pending';

const REG_TRACE_LINE = /\s*(.+)\((.+):([0-9]+):([0-9]+)\)$/;

class TapReporter {
constructor (globalConfig = {}, options = {}) {
const {logLevel = 'INFO'} = options;
Expand All @@ -24,9 +26,20 @@ class TapReporter {
this.onAssertionResult = this.onAssertionResult.bind(this);
}

formatFailureMessage (message, assertiontResult) {
formatFailureMessageTraceLine (line) {
const matches = line.match(REG_TRACE_LINE);

if (matches) {
const [, description, file, row, column] = matches;

return chalk`${description}({cyan ${file}}:{black.bold ${row}}:{black.bold ${column}})`;
} else {
return line;
}
}

formatFailureMessage (message) {
const [firstLine, ...lines] = message.split('\n');
const {duration} = assertiontResult;
const formattedLines = [];
const whitespace = ' '.repeat(9 + String(this.counter).length);

Expand All @@ -36,21 +49,25 @@ class TapReporter {
formattedLines.push(formattedLine);
};

const pushTraceLine = (line) => {
push(chalk` {grey ${line}}`);
};

push('');
push(firstLine);
push('');

for (const line of lines) {
push(line);
pushTraceLine(this.formatFailureMessageTraceLine(line));
}

push('');

return formattedLines.join('\n');
}

formatFailureMessages (messages, assertiontResult) {
return messages.map((message) => this.formatFailureMessage(message, assertiontResult)).join('\n');
formatFailureMessages (messages) {
return messages.map((message) => this.formatFailureMessage(message)).join('\n');
}

onAssertionResult (assertiontResult) {
Expand All @@ -65,12 +82,12 @@ class TapReporter {
switch (status) {
case STATUS_PASSED:
if (!this._watch) {
formattedLine = chalk`{green ok} ${counter} ${formattedTitle}`;
formattedLine = chalk`{green ok} {grey.dim ${counter}} ${formattedTitle}`;
}
break;
case STATUS_FAILED:
formattedLine = chalk`{red not ok} ${counter} {red.bold ● ${formattedTitle}}`;
formattedDiagnostics = this.formatFailureMessages(failureMessages, assertiontResult);
formattedLine = chalk`{red not ok} {grey.dim ${counter}} {red.bold ● ${formattedTitle}}`;
formattedDiagnostics = this.formatFailureMessages(failureMessages);
break;
case STATUS_PENDING:
formattedLine = chalk`{yellow ok} {bgYellow.rgba(255,255,255) ${counter}} ${formattedTitle} {yellow # SKIP}`;
Expand Down

0 comments on commit e3595c0

Please sign in to comment.