/
toTestResult.ts
81 lines (75 loc) · 1.97 KB
/
toTestResult.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import type { TestResult } from '@jest/test-result';
interface Options {
stats: {
failures: number;
passes: number;
pending: number;
todo: number;
start: number;
end: number;
};
skipped: boolean;
errorMessage?: string | null;
tests: Array<{
duration?: number | null;
errorMessage?: string;
testPath?: string;
title?: string;
}>;
jestTestPath: string;
}
function getPerfStats({ stats }: Options): TestResult['perfStats'] {
const start = new Date(stats.start).getTime();
const end = new Date(stats.end).getTime();
const runtime = end - start;
// Note: this flag is set in 'lib/createJestRunner.ts'
const slow = false;
return { start, end, runtime, slow };
}
function getSnapshot(): TestResult['snapshot'] {
return {
added: 0,
fileDeleted: false,
matched: 0,
unchecked: 0,
uncheckedKeys: [],
unmatched: 0,
updated: 0,
};
}
function getTestResults({
errorMessage,
tests,
jestTestPath,
}: Options): TestResult['testResults'] {
return tests.map(test => {
const actualErrorMessage = errorMessage || test.errorMessage;
return {
ancestorTitles: [],
duration: test.duration,
failureDetails: [],
failureMessages: actualErrorMessage ? [actualErrorMessage] : [],
fullName: jestTestPath || test.testPath || '',
numPassingAsserts: test.errorMessage ? 1 : 0,
status: test.errorMessage ? 'failed' : 'passed',
title: test.title || '',
};
});
}
export default function toTestResult(options: Options): TestResult {
const { stats, skipped, errorMessage, jestTestPath } = options;
return {
failureMessage: errorMessage,
leaks: false,
numFailingTests: stats.failures,
numPassingTests: stats.passes,
numPendingTests: stats.pending,
numTodoTests: stats.todo,
openHandles: [],
perfStats: getPerfStats(options),
skipped,
snapshot: getSnapshot(),
testFilePath: jestTestPath,
testResults: getTestResults(options),
};
}