-
Notifications
You must be signed in to change notification settings - Fork 299
/
Copy pathTestResult.ts
152 lines (127 loc) · 4.06 KB
/
TestResult.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import { TestReconciliationStateType } from './TestReconciliationState';
import { CoverageMap, FileCoverage } from 'istanbul-lib-coverage';
import * as path from 'path';
import { cleanAnsi, toLowerCaseDriveLetter } from '../helpers';
import { MatchEvent } from './match-node';
import type { AggregatedResult, TestResult as JestTestResult } from '@jest/reporters';
export interface Location {
/** Zero-based column number */
column: number;
/** Zero-based line number */
line: number;
}
export interface LocationRange {
start: Location;
end: Location;
}
export interface TestIdentifier {
title: string;
ancestorTitles: string[];
}
export interface TestResult extends LocationRange {
name: string;
identifier: TestIdentifier;
status: TestReconciliationStateType;
shortMessage?: string;
terseMessage?: string;
/** Zero-based line number */
lineNumberOfError?: number;
// multiple results for the given range, common for parameterized (.each) tests
multiResults?: TestResult[];
// matching process history
sourceHistory?: MatchEvent[];
assertionHistory?: MatchEvent[];
}
function testResultWithLowerCaseWindowsDriveLetter(testResult: JestTestResult): JestTestResult {
const newFilePath = toLowerCaseDriveLetter(testResult.testFilePath);
if (newFilePath) {
return {
...testResult,
testFilePath: newFilePath,
};
}
return testResult;
}
export const testResultsWithLowerCaseWindowsDriveLetters = (
testResults: JestTestResult[]
): JestTestResult[] => {
if (!testResults) {
return testResults;
}
return testResults.map(testResultWithLowerCaseWindowsDriveLetter);
};
function fileCoverageWithLowerCaseWindowsDriveLetter(fileCoverage: FileCoverage) {
const newFilePath = toLowerCaseDriveLetter(fileCoverage.path);
if (newFilePath) {
return {
...fileCoverage,
path: newFilePath,
};
}
return fileCoverage;
}
export const coverageMapWithLowerCaseWindowsDriveLetters = (data: AggregatedResult): CoverageMap | undefined => {
if (!data.coverageMap) {
return;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const result: any = {};
for (const filePath of data.coverageMap.files()) {
const newFileCoverage = fileCoverageWithLowerCaseWindowsDriveLetter(data.coverageMap.fileCoverageFor(filePath));
result[newFileCoverage.path] = newFileCoverage;
}
return result;
};
/**
* Normalize file paths on Windows systems to use lowercase drive letters.
* This follows the standard used by Visual Studio Code for URIs which includes
* the document fileName property.
*
* @param data Parsed JSON results
*/
export const resultsWithLowerCaseWindowsDriveLetters = (
data: AggregatedResult
): AggregatedResult => {
if (path.sep === '\\') {
return {
...data,
coverageMap: coverageMapWithLowerCaseWindowsDriveLetters(data),
testResults: testResultsWithLowerCaseWindowsDriveLetters(data.testResults),
};
}
return data;
};
/**
* Removes ANSI escape sequence characters from test results in order to get clean messages
*/
export const resultsWithoutAnsiEscapeSequence = (data: AggregatedResult): AggregatedResult => {
if (!data || !data.testResults) {
return data;
}
return {
...data,
testResults: data.testResults.map((result) => ({
...result,
failureMessage: cleanAnsi(result.failureMessage),
testResults: result.testResults.map((assertion) => ({
...assertion,
failureMessages: assertion.failureMessages.map((message) => cleanAnsi(message)),
})),
})),
};
};
// export type StatusInfo<T> = {[key in TestReconciliationState]: T};
export interface StatusInfo {
precedence: number;
desc: string;
}
export const TestResultStatusInfo: { [key in TestReconciliationStateType]: StatusInfo } = {
KnownFail: { precedence: 1, desc: 'Failed' },
Unknown: {
precedence: 2,
desc: 'Test has not run yet, due to Jest only running tests related to changes.',
},
KnownSkip: { precedence: 3, desc: 'Skipped' },
KnownSuccess: { precedence: 4, desc: 'Passed' },
KnownTodo: { precedence: 5, desc: 'Todo' },
};