revert reporters

This commit is contained in:
Yury Semikhatsky 2024-10-16 17:12:39 -07:00
parent 3c9895588a
commit 896ea2dd67
5 changed files with 19 additions and 56 deletions

View file

@ -14,7 +14,7 @@
limitations under the License.
*/
import type { ErrorDetails, TestAttachment, TestCase, TestResult, TestStep } from './types';
import type { TestAttachment, TestCase, TestResult, TestStep } from './types';
import * as React from 'react';
import { TreeItem } from './treeItem';
import { msToString } from './utils';
@ -150,30 +150,26 @@ export const TestResultView: React.FC<{
</div>;
};
function classifyErrors(testErrors: ErrorDetails[], diffs: ImageDiff[]) {
function classifyErrors(testErrors: string[], diffs: ImageDiff[]) {
return testErrors.map(error => {
if (error.shortMessage?.includes('Screenshot comparison failed:') && error.actual && error.expected) {
if (error.includes('Screenshot comparison failed:')) {
const matchingDiff = diffs.find(diff => {
const attachmentName = diff.actual?.attachment.name;
return attachmentName && error.actual.endsWith(attachmentName);
return attachmentName && error.includes(attachmentName);
});
const errorSuffix = ['Call log:',
...(error.log?.map(line => ' - ' + line) || []),
'',
error.snippet,
'',
error.callStack,
].join('\n');
if (matchingDiff) {
return {
type: 'screenshot',
diff: matchingDiff,
errorPrefix: error.shortMessage,
errorSuffix
};
const lines = error.split('\n');
const index = lines.findIndex(line => /Expected:|Previous:|Received:/.test(line));
const errorPrefix = index !== -1 ? lines.slice(0, index).join('\n') : lines[0];
const diffIndex = lines.findIndex(line => / +Diff:/.test(line));
const errorSuffix = diffIndex !== -1 ? lines.slice(diffIndex + 2).join('\n') : lines.slice(1).join('\n');
return { type: 'screenshot', diff: matchingDiff, errorPrefix, errorSuffix };
}
}
return { type: 'regular', error: error.message };
return { type: 'regular', error };
});
}

View file

@ -83,17 +83,6 @@ export type TestCase = Omit<TestCaseSummary, 'results'> & {
results: TestResult[];
};
export type ErrorDetails = {
message: string;
location?: Location;
shortMessage?: string;
log?: string[];
expected?: any;
actual?: any;
snippet?: string;
callStack?: string;
};
export type TestAttachment = {
name: string;
body?: string;
@ -106,7 +95,7 @@ export type TestResult = {
startTime: string;
duration: number;
steps: TestStep[];
errors: ErrorDetails[];
errors: string[];
attachments: TestAttachment[];
status: 'passed' | 'failed' | 'timedOut' | 'skipped' | 'interrupted';
};

View file

@ -32,17 +32,6 @@ type Annotation = {
type ErrorDetails = {
message: string;
location?: Location;
callStack?: string;
};
type TestResultErrorDetails = ErrorDetails & {
shortMessage?: string;
log?: string[];
expected?: any;
actual?: any;
snippet?: string;
stack?: string;
};
type TestSummary = {
@ -375,8 +364,8 @@ function quotePathIfNeeded(path: string): string {
return path;
}
export function formatResultFailure(test: TestCase, result: TestResult, initialIndent: string, highlightCode: boolean): TestResultErrorDetails[] {
const errorDetails: TestResultErrorDetails[] = [];
export function formatResultFailure(test: TestCase, result: TestResult, initialIndent: string, highlightCode: boolean): ErrorDetails[] {
const errorDetails: ErrorDetails[] = [];
if (result.status === 'passed' && test.expectedStatus === 'failed') {
errorDetails.push({
@ -394,12 +383,6 @@ export function formatResultFailure(test: TestCase, result: TestResult, initialI
errorDetails.push({
message: indent(formattedError.message, initialIndent),
location: formattedError.location,
shortMessage: error.shortMessage,
log: error.log,
expected: error.expected,
actual: error.actual,
snippet: error.snippet,
callStack: formattedError.callStack,
});
}
return errorDetails;
@ -479,12 +462,9 @@ export function formatError(error: TestError, highlightCode: boolean): ErrorDeta
tokens.push(snippet);
}
let callStack;
if (parsedStack && parsedStack.stackLines.length) {
tokens.push('');
tokens.push(colors.dim(parsedStack.stackLines.join('\n')));
// TODO: pass raw lines.
callStack = colors.dim(parsedStack.stackLines.join('\n'));
}
let location = error.location;
@ -494,7 +474,6 @@ export function formatError(error: TestError, highlightCode: boolean): ErrorDeta
return {
location,
message: tokens.join('\n'),
callStack,
};
}

View file

@ -485,7 +485,7 @@ class HtmlBuilder {
startTime: result.startTime.toISOString(),
retry: result.retry,
steps: dedupeSteps(result.steps).map(s => this._createTestStep(s)),
errors: formatResultFailure(test, result, '', true),
errors: formatResultFailure(test, result, '', true).map(error => error.message),
status: result.status,
attachments: this._serializeAttachments([
...result.attachments,

View file

@ -222,8 +222,7 @@ class JSONReporter implements ReporterV2 {
}
private _serializeError(error: TestError): JSONReportError {
const { message, location } = formatError(error, true);
return { message, location };
return formatError(error, true);
}
private _serializeTestStep(step: TestStep): JSONReportTestStep {