@tapjs/node-serialize
Version:
Stream TAP test data as a serialized node:test stream
43 lines • 1.69 kB
JavaScript
;
// turn a tap-parser Result object into an Error
// Put some of the diagnostic info into the error message,
// because that is the string the node --test reporter shows.
Object.defineProperty(exports, "__esModule", { value: true });
exports.resultToError = void 0;
const stack_1 = require("@tapjs/stack");
const loc_from_callsite_js_1 = require("./loc-from-callsite.js");
const pretty_diff_js_1 = require("./pretty-diff.js");
const resultToError = (result, test) => {
const { stack: diagStack, diff: rawDiff, source, passes: _, ...diag } = result.diag || {};
const at = diag.at ?? test?.options.at;
const lfa = !!at ? (0, loc_from_callsite_js_1.locFromCallSite)(at) : undefined;
const stack = diagStack ||
(lfa?.file ? `${lfa.file}:${lfa.line}:${lfa.column}` : undefined);
delete diag.at;
const diff = (0, pretty_diff_js_1.prettyDiff)(rawDiff);
if (diff) {
delete diag.actual;
delete diag.expected;
delete diag.found;
delete diag.wanted;
}
else if (result.diag) {
if ('found' in diag) {
diag.actual = diag.found;
}
if ('wanted' in diag) {
diag.expected = diag.wanted;
}
delete diag.found;
delete diag.wanted;
}
const name = (result.name || result.tapError || 'unnamed test') +
(diff ? '\n' + diff : '') +
(source ? '\n| ' + source.trimEnd().split('\n').join('\n| ') : '');
return Object.assign(new Error(name), {
...diag,
stack: `Error: ${name}\n` + (0, stack_1.expandStack)(stack).trimEnd(),
});
};
exports.resultToError = resultToError;
//# sourceMappingURL=result-to-error.js.map