From 896ea2dd671b04c967acdbdc9ad11180b8d0aa40 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Wed, 16 Oct 2024 17:12:39 -0700 Subject: [PATCH] revert reporters --- packages/html-reporter/src/testResultView.tsx | 32 ++++++++----------- packages/html-reporter/src/types.ts | 13 +------- packages/playwright/src/reporters/base.ts | 25 ++------------- packages/playwright/src/reporters/html.ts | 2 +- packages/playwright/src/reporters/json.ts | 3 +- 5 files changed, 19 insertions(+), 56 deletions(-) diff --git a/packages/html-reporter/src/testResultView.tsx b/packages/html-reporter/src/testResultView.tsx index 525e1a484f..48a24a2391 100644 --- a/packages/html-reporter/src/testResultView.tsx +++ b/packages/html-reporter/src/testResultView.tsx @@ -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<{ ; }; -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 }; }); } diff --git a/packages/html-reporter/src/types.ts b/packages/html-reporter/src/types.ts index ad06ba1b6e..733e88e8b9 100644 --- a/packages/html-reporter/src/types.ts +++ b/packages/html-reporter/src/types.ts @@ -83,17 +83,6 @@ export type TestCase = Omit & { 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'; }; diff --git a/packages/playwright/src/reporters/base.ts b/packages/playwright/src/reporters/base.ts index f27b803389..4249429a36 100644 --- a/packages/playwright/src/reporters/base.ts +++ b/packages/playwright/src/reporters/base.ts @@ -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, }; } diff --git a/packages/playwright/src/reporters/html.ts b/packages/playwright/src/reporters/html.ts index 9c6a92be20..5aada7e495 100644 --- a/packages/playwright/src/reporters/html.ts +++ b/packages/playwright/src/reporters/html.ts @@ -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, diff --git a/packages/playwright/src/reporters/json.ts b/packages/playwright/src/reporters/json.ts index df66bf5d4b..e2b7ddf872 100644 --- a/packages/playwright/src/reporters/json.ts +++ b/packages/playwright/src/reporters/json.ts @@ -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 {