1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.default = formatTestResults;
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | const formatTestResult = (testResult, codeCoverageFormatter, reporter) => {
|
15 | const assertionResults = testResult.testResults.map(formatTestAssertion);
|
16 |
|
17 | if (testResult.testExecError) {
|
18 | const now = Date.now();
|
19 | return {
|
20 | assertionResults,
|
21 | coverage: {},
|
22 | endTime: now,
|
23 | message: testResult.failureMessage
|
24 | ? testResult.failureMessage
|
25 | : testResult.testExecError.message,
|
26 | name: testResult.testFilePath,
|
27 | startTime: now,
|
28 | status: 'failed',
|
29 | summary: ''
|
30 | };
|
31 | } else {
|
32 | const allTestsPassed = testResult.numFailingTests === 0;
|
33 | return {
|
34 | assertionResults,
|
35 | coverage: codeCoverageFormatter
|
36 | ? codeCoverageFormatter(testResult.coverage, reporter)
|
37 | : testResult.coverage,
|
38 | endTime: testResult.perfStats.end,
|
39 | message: testResult.failureMessage || '',
|
40 | name: testResult.testFilePath,
|
41 | startTime: testResult.perfStats.start,
|
42 | status: allTestsPassed ? 'passed' : 'failed',
|
43 | summary: ''
|
44 | };
|
45 | }
|
46 | };
|
47 |
|
48 | function formatTestAssertion(assertion) {
|
49 | const result = {
|
50 | ancestorTitles: assertion.ancestorTitles,
|
51 | failureMessages: null,
|
52 | fullName: assertion.fullName,
|
53 | location: assertion.location,
|
54 | status: assertion.status,
|
55 | title: assertion.title
|
56 | };
|
57 |
|
58 | if (assertion.failureMessages) {
|
59 | result.failureMessages = assertion.failureMessages;
|
60 | }
|
61 |
|
62 | return result;
|
63 | }
|
64 |
|
65 | function formatTestResults(results, codeCoverageFormatter, reporter) {
|
66 | const testResults = results.testResults.map(testResult =>
|
67 | formatTestResult(testResult, codeCoverageFormatter, reporter)
|
68 | );
|
69 | return {...results, testResults};
|
70 | }
|