Skip to content

Commit

Permalink
Handle jest suites that failed to run (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
yurynix authored Sep 23, 2020
1 parent cc3374f commit bcaec37
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion __tests__/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
{ "ancestorTitles": ["path2", "to", "constructor"], "title": "title6", "status": "passed", "duration": 123 }
]
}
]
]
19 changes: 19 additions & 0 deletions __tests__/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<anonymous>: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.<anonymous>: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']"],
]);
});
});
});
16 changes: 13 additions & 3 deletions lib/formatter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

const path = require("path");
const errorMessageStackSeparator = "\n ";

module.exports = {
/**
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit bcaec37

Please sign in to comment.