Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 25 additions & 64 deletions lib/reporters/tap.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';
const format = require('util').format;
const indentString = require('indent-string');
const supertap = require('supertap');
const stripAnsi = require('strip-ansi');
const yaml = require('js-yaml');

function dumpError(error, includeMessage) {
const obj = Object.assign({}, error.object);
Expand Down Expand Up @@ -32,7 +30,7 @@ function dumpError(error, includeMessage) {
obj.at = error.stack.split('\n')[0];
}

return ` ---\n${indentString(yaml.safeDump(obj).trim(), 4)}\n ...`;
return obj;
}

class TapReporter {
Expand All @@ -41,79 +39,42 @@ class TapReporter {
}

start() {
return 'TAP version 13';
return supertap.start();
}

test(test) {
const output = [];

let directive = '';
const passed = test.todo ? 'not ok' : 'ok';

if (test.todo) {
directive = '# TODO';
} else if (test.skip) {
directive = '# SKIP';
}

const title = stripAnsi(test.title);

const appendLogs = () => {
if (test.logs) {
test.logs.forEach(log => {
const logLines = indentString(log, 4);
const logLinesWithLeadingFigure = logLines.replace(
/^ {4}/,
' * '
);

output.push(logLinesWithLeadingFigure);
});
}
};

output.push(`# ${title}`);

if (test.error) {
output.push(format('not ok %d - %s', ++this.i, title));
appendLogs();
output.push(dumpError(test.error, true));
} else {
output.push(format('%s %d - %s %s', passed, ++this.i, title, directive).trim());
appendLogs();
}

return output.join('\n');
return supertap.test(test.title, {
passed: !test.error,
index: ++this.i,
todo: test.todo,
skip: test.skip,
comment: test.logs,
error: test.error ? dumpError(test.error, true) : null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dumpError doesn't return an Error instance, which supertaps API says is expected. Perhaps the API documentation should be loosened, or clearer on what properties are expected on non-Error objects?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, will clarify that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

});
}

unhandledError(err) {
const output = [
`# ${err.message}`,
format('not ok %d - %s', ++this.i, err.message)
];
let error;

// AvaErrors don't have stack traces
if (err.type !== 'exception' || err.name !== 'AvaError') {
output.push(dumpError(err, false));
error = dumpError(err, false);
}

return output.join('\n');
return supertap.test(err.message, {
passed: false,
index: ++this.i,
error
});
}

finish(runStatus) {
const output = [
'',
'1..' + (runStatus.passCount + runStatus.failCount + runStatus.skipCount),
'# tests ' + (runStatus.passCount + runStatus.failCount + runStatus.skipCount),
'# pass ' + runStatus.passCount
];

if (runStatus.skipCount > 0) {
output.push(`# skip ${runStatus.skipCount}`);
}

output.push('# fail ' + (runStatus.failCount + runStatus.rejectionCount + runStatus.exceptionCount), '');

return output.join('\n');
return supertap.finish({
passed: runStatus.passCount,
failed: runStatus.failCount,
skipped: runStatus.skipCount,
crashed: runStatus.rejectionCount + runStatus.exceptionCount
});
}

write(str) {
Expand Down
42 changes: 41 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
"is-obj": "^1.0.0",
"is-observable": "^1.0.0",
"is-promise": "^2.1.0",
"js-yaml": "^3.8.2",
"last-line-stream": "^1.0.0",
"lodash.clonedeepwith": "^4.5.0",
"lodash.debounce": "^4.0.3",
Expand Down Expand Up @@ -139,6 +138,7 @@
"stack-utils": "^1.0.1",
"strip-ansi": "^4.0.0",
"strip-bom-buf": "^1.0.0",
"supertap": "^1.0.0",
"supports-color": "^5.0.0",
"time-require": "^0.1.2",
"trim-off-newlines": "^1.0.1",
Expand Down