UNPKG

@tapjs/node-serialize

Version:

Stream TAP test data as a serialized node:test stream

78 lines 2.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.testResults = void 0; const stack_1 = require("@tapjs/stack"); const result_to_error_js_1 = require("./result-to-error.js"); const test_message_data_js_1 = require("./test-message-data.js"); const testResults = (t, count, testNumber) => { if (!t.parent) return; const results = t.results; /* c8 ignore start */ if (!results) { throw new Error('printing messages before results available'); } /* c8 ignore stop */ const suite = count > 0; const p = { ...(0, test_message_data_js_1.testMessageData)(t), details: { duration_ms: t.time, }, testNumber, }; const skip = results.plan.skipAll ? results.plan.skipReason || true : t.options.skip; if (skip) p.skip = skip; const todo = t.options.todo; if (todo) p.todo = todo; if (suite) p.details.type = 'suite'; if (results.ok) return p; if (suite) { const nf = results.failures.length; const m = `${nf} subtest${nf === 1 ? '' : 's'} failed`; return { ...p, details: { ...p.details, error: Object.assign(new Error(m), { code: 'ERR_TEST_FAILURE', failureType: 'subtestsFailed', cause: m, /* c8 ignore start */ failures: results.failures.map(f => f.name || f.tapError), stack: t.options.stack ? (0, stack_1.expandStack)(t.options.stack) : undefined, /* c8 ignore stop */ }), }, }; } // a failure here indicates a strange test that had no failing test points, // but then was marked as not ok. const fe = (0, result_to_error_js_1.resultToError)(t.lists.fail[0] ?? results.failures[0] ?? { ok: false, name: 'Unknown test failure', diag: {}, }, t); return { ...p, details: { ...p.details, error: Object.assign(new Error(fe.message), { cause: fe, code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', /* c8 ignore start */ failures: results.failures.map(f => f.name || f.tapError), /* c8 ignore stop */ stack: (0, stack_1.expandStack)(t.options.stack).trimEnd(), }), }, }; }; exports.testResults = testResults; //# sourceMappingURL=test-results.js.map