class TestSamuraiJestReporter { constructor(_globalConfig, _options) {} onTestCaseResult(test, testCaseResult) { const name = this.buildListingName(testCaseResult); const jestName = this.buildJestName(testCaseResult); const payload = { name, jestName, status: testCaseResult.status, file: test && test.path ? test.path : null, location: testCaseResult.location || null, output: this.buildOutput(testCaseResult), }; process.stdout.write(`TSAMURAI_RESULT ${JSON.stringify(payload)}\n`); } buildListingName(testCaseResult) { const ancestors = Array.isArray(testCaseResult.ancestorTitles) ? testCaseResult.ancestorTitles : []; const title = testCaseResult.title ? String(testCaseResult.title) : ""; return [...ancestors, title].filter(Boolean).join("/"); } buildJestName(testCaseResult) { const ancestors = Array.isArray(testCaseResult.ancestorTitles) ? testCaseResult.ancestorTitles : []; const title = testCaseResult.title ? String(testCaseResult.title) : ""; return [...ancestors, title].filter(Boolean).join(" "); } buildOutput(testCaseResult) { const lines = []; const failures = Array.isArray(testCaseResult.failureMessages) ? testCaseResult.failureMessages : []; failures.forEach((message) => { if (typeof message === "string" && message.length > 0) { message.split("\n").forEach((line) => { if (line !== "") { lines.push(line); } }); } }); return lines; } } module.exports = TestSamuraiJestReporter;