(tests, oldTestsData, expectedSource, expectedVersion)
| 74 | } |
| 75 | |
| 76 | function processTestsData(tests, oldTestsData, expectedSource, expectedVersion) { |
| 77 | tests.forEach((test, idx) => { |
| 78 | let passed = 0; |
| 79 | test.index = idx; |
| 80 | test.results.forEach(result => { |
| 81 | // Threshold? |
| 82 | if (result.diffRatio < 0.0001) { |
| 83 | passed++; |
| 84 | } |
| 85 | let timestamp = test.lastRun || 0; |
| 86 | result.diff = result.diff + '?' + timestamp; |
| 87 | result.actual = result.actual + '?' + timestamp; |
| 88 | result.expected = result.expected + '?' + timestamp; |
| 89 | }); |
| 90 | test.percentage = passed === 0 ? 0 : Math.round(passed / test.results.length * 100); |
| 91 | if (test.percentage === 100) { |
| 92 | test.summary = 'success'; |
| 93 | } |
| 94 | else if (shouldShowMarkAsExpected(test, expectedSource, expectedVersion)) { |
| 95 | test.summary = 'markedAsExpected'; |
| 96 | } |
| 97 | else if (test.percentage < 50) { |
| 98 | test.summary = 'exception'; |
| 99 | } |
| 100 | else { |
| 101 | test.summary = 'warning'; |
| 102 | } |
| 103 | |
| 104 | // To simplify the condition in sort |
| 105 | test.actualErrors = test.actualErrors || []; |
| 106 | |
| 107 | // Format date for marks display |
| 108 | if (test.markedAsExpected) { |
| 109 | test.markedAsExpected.forEach(mark => { |
| 110 | if (mark.markTime && !mark.markTimeFormatted) { |
| 111 | mark.markTimeFormatted = formatDate(mark.markTime); |
| 112 | } |
| 113 | }); |
| 114 | } |
| 115 | |
| 116 | // Keep select status not change. |
| 117 | if (oldTestsData && oldTestsData[idx]) { |
| 118 | test.selected = oldTestsData[idx].selected; |
| 119 | // Keep source information |
| 120 | test.expectedSource = oldTestsData[idx].expectedSource; |
| 121 | test.actualSource = oldTestsData[idx].actualSource; |
| 122 | |
| 123 | // If old data has markedAsExpected but new data doesn't, keep the old data. |
| 124 | if (oldTestsData[idx].markedAsExpected && !test.markedAsExpected) { |
| 125 | test.markedAsExpected = oldTestsData[idx].markedAsExpected; |
| 126 | } |
| 127 | |
| 128 | // Ensure markedAsExpected is null when it's empty |
| 129 | if (test.markedAsExpected && Array.isArray(test.markedAsExpected) && test.markedAsExpected.length === 0) { |
| 130 | test.markedAsExpected = null; |
| 131 | } |
| 132 | } |
| 133 | else { |
no test coverage detected
searching dependent graphs…