Skip to content

Commit 2028f1f

Browse files
author
Yohay Nahmany
authored
Merge pull request #252 from currents-dev/fix/jest-test-status
[CSR-2745] fix: report correct test status for jest reporter
2 parents 31fbe71 + 50a59dd commit 2028f1f

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/jest/src/lib/test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Test, TestCaseResult } from '@jest/reporters';
22
import type { Circus } from '@jest/types';
3+
import { maxBy } from 'lodash';
34
import crypto from 'node:crypto';
45
import {
56
ExpectedStatus,
@@ -106,13 +107,18 @@ export function getExpectedStatus(status: JestTestCaseStatus): ExpectedStatus {
106107
}
107108
}
108109

109-
export function jestStatusFromInvocations(testResults: TestCaseResult[]) {
110-
const statuses = testResults.map((r) => r.status as JestTestCaseStatus);
111-
if (statuses.every((status) => status === statuses[0])) {
112-
return statuses[0];
110+
export function jestStatusFromInvocations(
111+
testResults: TestCaseResult[]
112+
): JestTestCaseStatus {
113+
if (testResults.length === 0) {
114+
return 'failed';
113115
}
114116

115-
return 'failed';
117+
const resultWithMaxInvocation =
118+
maxBy(testResults, (r) => r.invocations ?? 0) ??
119+
testResults[testResults.length - 1];
120+
121+
return resultWithMaxInvocation.status as JestTestCaseStatus;
116122
}
117123

118124
export function getAttemptNumber(result: TestCaseResult) {

0 commit comments

Comments
 (0)