From bcaec37254861aa7aa7772d4ad5b63a35fa50632 Mon Sep 17 00:00:00 2001 From: Yury Michurin Date: Wed, 23 Sep 2020 17:43:17 +0300 Subject: [PATCH] Handle jest suites that failed to run (#16) --- __tests__/data.json | 2 +- __tests__/formatter.js | 19 +++++++++++++++++++ lib/formatter.js | 16 +++++++++++++--- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/__tests__/data.json b/__tests__/data.json index c8adef0..4ac0b45 100644 --- a/__tests__/data.json +++ b/__tests__/data.json @@ -15,4 +15,4 @@ { "ancestorTitles": ["path2", "to", "constructor"], "title": "title6", "status": "passed", "duration": 123 } ] } -] +] \ No newline at end of file diff --git a/__tests__/formatter.js b/__tests__/formatter.js index 03f06ff..7d58639 100644 --- a/__tests__/formatter.js +++ b/__tests__/formatter.js @@ -138,5 +138,24 @@ test3`) formatter.formatReport(testData, "/Users/test/", "12345"); expect(console.log.mock.calls).toEqual(consoleOutput); }); + + test("textExecError", () => { + formatter.formatReport([{ + "testFilePath": "/Users/spec-with-error/failing.spec.ts", + "testResults": [], + "testExecError": { + "message": "Error:\nSomething bad is happened!", + "stack": "Error: Timeout of 181000 waiting for jest process 168 reached!\nThat means that your test suite, the spec file, took too much time to execute. Try spliting the spec to multiple specs.\n at Timeout._onTimeout (evalmachine.:1901:31)\n at listOnTimeout (internal/timers.js:549:17)\n at processTimers (internal/timers.js:492:7)", + "type": "Error" + } + }], "/Users/spec-with-error", "12345"); + expect(console.log.mock.calls).toEqual([ + ["##teamcity[testSuiteStarted name='failing.spec.ts' flowId='12345']"], + ["##teamcity[testStarted name='Jest failed to execute suite' flowId='12345']"], + ["##teamcity[testFailed name='Jest failed to execute suite' message='Error:|nSomething bad is happened!' details='Error: Timeout of 181000 waiting for jest process 168 reached!|nThat means that your test suite, the spec file, took too much time to execute. Try spliting the spec to multiple specs.|n at Timeout._onTimeout (evalmachine.:1901:31)|n at listOnTimeout (internal/timers.js:549:17)|n at processTimers (internal/timers.js:492:7)' flowId='12345']"], + ["##teamcity[testFinished name='Jest failed to execute suite' duration='0' flowId='12345']"], + ["##teamcity[testSuiteFinished name='failing.spec.ts' flowId='12345']"], + ]); + }); }); }); diff --git a/lib/formatter.js b/lib/formatter.js index a7ec500..956d7a8 100644 --- a/lib/formatter.js +++ b/lib/formatter.js @@ -1,6 +1,7 @@ "use strict"; const path = require("path"); +const errorMessageStackSeparator = "\n "; module.exports = { /** @@ -42,12 +43,11 @@ module.exports = { case "failed": if (test.failureMessages) { test.failureMessages.forEach(error => { - const separator = "\n "; - const [message, ...stack] = error.split(separator); + const [message, ...stack] = error.split(errorMessageStackSeparator); this.log( `##teamcity[testFailed name='${this.escape(test.title)}' message='${this.escape( message - )}' details='${this.escape(stack.join(separator))}' flowId='${flowId}']` + )}' details='${this.escape(stack.join(errorMessageStackSeparator))}' flowId='${flowId}']` ); }); } else { @@ -123,6 +123,16 @@ module.exports = { // add the current test currentSuite["_tests_"].push(test); }); + + if (testFile.testExecError && testFile.testResults.length === 0) { + suites[filename] = suites[filename] || {}; + suites[filename]['_tests_'] = [{ + status: 'failed', + title: 'Jest failed to execute suite', + duration: 0, + failureMessages: [`${testFile.testExecError.message}${errorMessageStackSeparator}${testFile.testExecError.stack}`], + }]; + } }); return suites;