Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: remove error context JSON format (#36116)
Simon Knottd1df5893bca6
diff --git a/packages/playwright/src/errorContext.ts b/packages/playwright/src/errorContext.tsindex c6b21d6952..6a1ce50ee8 100644--- a/packages/playwright/src/errorContext.ts+++ b/packages/playwright/src/errorContext.ts@@ -26,22 +26,7 @@ import type { MetadataWithCommitInfo } from './isomorphic/types';import type { TestInfoImpl } from './worker/testInfo';import type { Location } from '../types/test';-export async function attachErrorContext(testInfo: TestInfoImpl, format: 'markdown' | 'json', sourceCache: Map<string, string>, ariaSnapshot: string | undefined) {- if (format === 'json') {- if (!ariaSnapshot)- return;-- testInfo._attach({- name: `error-context`,- contentType: 'application/json',- body: Buffer.from(JSON.stringify({- pageSnapshot: ariaSnapshot,- })),- }, undefined);-- return;- }-+export async function attachErrorContext(testInfo: TestInfoImpl, sourceCache: Map<string, string>, ariaSnapshot: string | undefined) {const meaningfulSingleLineErrors = new Set(testInfo.errors.filter(e => e.message && !e.message.includes('\n')).map(e => e.message!));for (const error of testInfo.errors) {for (const singleLineError of meaningfulSingleLineErrors.keys()) {diff --git a/packages/playwright/src/index.ts b/packages/playwright/src/index.tsindex 9aff812c6b..a59b719416 100644--- a/packages/playwright/src/index.ts+++ b/packages/playwright/src/index.ts@@ -56,15 +56,12 @@ type TestFixtures = PlaywrightTestArgs & PlaywrightTestOptions & {_contextFactory: (options?: BrowserContextOptions) => Promise<BrowserContext>;};-type ErrorContextOption = { format: 'json' | 'markdown' } | undefined;-type WorkerFixtures = PlaywrightWorkerArgs & PlaywrightWorkerOptions & {playwright: PlaywrightImpl;_browserOptions: LaunchOptions;_optionContextReuseMode: ContextReuseMode,_optionConnectOptions: PlaywrightWorkerOptions['connectOptions'],_reuseContext: boolean,- _optionErrorContext: ErrorContextOption,};const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({@@ -248,13 +245,13 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({playwright._defaultContextNavigationTimeout = undefined;}, { auto: 'all-hooks-included', title: 'context configuration', box: true } as any],- _setupArtifacts: [async ({ playwright, screenshot, _optionErrorContext }, use, testInfo) => {+ _setupArtifacts: [async ({ playwright, screenshot }, use, testInfo) => {// This fixture has a separate zero-timeout slot to ensure that artifact collection// happens even after some fixtures or hooks time out.// Now that default test timeout is known, we can replace zero with an actual value.testInfo.setTimeout(testInfo.project.timeout);- const artifactsRecorder = new ArtifactsRecorder(playwright, tracing().artifactsDir(), screenshot, _optionErrorContext);+ const artifactsRecorder = new ArtifactsRecorder(playwright, tracing().artifactsDir(), screenshot);await artifactsRecorder.willStartTest(testInfo as TestInfoImpl);const tracingGroupSteps: TestStepInternal[] = [];@@ -400,7 +397,6 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({_optionContextReuseMode: ['none', { scope: 'worker', option: true }],_optionConnectOptions: [undefined, { scope: 'worker', option: true }],- _optionErrorContext: [process.env.PLAYWRIGHT_NO_COPY_PROMPT ? undefined : { format: 'markdown' }, { scope: 'worker', option: true }],_reuseContext: [async ({ video, _optionContextReuseMode }, use) => {let mode = _optionContextReuseMode;@@ -629,12 +625,10 @@ class ArtifactsRecorder {private _screenshotRecorder: SnapshotRecorder;private _pageSnapshot: string | undefined;private _sourceCache: Map<string, string> = new Map();- private _errorContext: ErrorContextOption;- constructor(playwright: PlaywrightImpl, artifactsDir: string, screenshot: ScreenshotOption, errorContext: ErrorContextOption) {+ constructor(playwright: PlaywrightImpl, artifactsDir: string, screenshot: ScreenshotOption) {this._playwright = playwright;this._artifactsDir = artifactsDir;- this._errorContext = errorContext;const screenshotOptions = typeof screenshot === 'string' ? undefined : screenshot;this._startedCollectingArtifacts = Symbol('startedCollectingArtifacts');@@ -678,7 +672,7 @@ class ArtifactsRecorder {}private async _takePageSnapshot(context: BrowserContext) {- if (!this._errorContext)+ if (process.env.PLAYWRIGHT_NO_COPY_PROMPT)return;if (this._testInfo.errors.length === 0)return;@@ -726,8 +720,8 @@ class ArtifactsRecorder {if (context)await this._takePageSnapshot(context);- if (this._errorContext)- await attachErrorContext(this._testInfo, this._errorContext.format, this._sourceCache, this._pageSnapshot);+ if (!process.env.PLAYWRIGHT_NO_COPY_PROMPT)+ await attachErrorContext(this._testInfo, this._sourceCache, this._pageSnapshot);}private async _startTraceChunkOnContextCreation(tracing: Tracing) {diff --git a/packages/playwright/src/isomorphic/testServerInterface.ts b/packages/playwright/src/isomorphic/testServerInterface.tsindex 5849168542..66136bab2e 100644--- a/packages/playwright/src/isomorphic/testServerInterface.ts+++ b/packages/playwright/src/isomorphic/testServerInterface.ts@@ -102,7 +102,6 @@ export interface TestServerInterface {projects?: string[];reuseContext?: boolean;connectWsEndpoint?: string;- errorContext?: { format: 'json' | 'markdown' };}): Promise<{status: reporterTypes.FullResult['status'];}>;diff --git a/packages/playwright/src/runner/testServer.ts b/packages/playwright/src/runner/testServer.tsindex 1f42186d95..61be3b2929 100644--- a/packages/playwright/src/runner/testServer.ts+++ b/packages/playwright/src/runner/testServer.ts@@ -316,7 +316,6 @@ export class TestServerDispatcher implements TestServerInterface {...(params.headed !== undefined ? { headless: !params.headed } : {}),_optionContextReuseMode: params.reuseContext ? 'when-possible' : undefined,_optionConnectOptions: params.connectWsEndpoint ? { wsEndpoint: params.connectWsEndpoint } : undefined,- _optionErrorContext: params.errorContext,},...(params.updateSnapshots ? { updateSnapshots: params.updateSnapshots } : {}),...(params.updateSourceMethod ? { updateSourceMethod: params.updateSourceMethod } : {}),diff --git a/tests/playwright-test/reporter-json.spec.ts b/tests/playwright-test/reporter-json.spec.tsindex c7fc8e519e..89b995ff35 100644--- a/tests/playwright-test/reporter-json.spec.ts+++ b/tests/playwright-test/reporter-json.spec.ts@@ -355,26 +355,3 @@ test('should report parallelIndex', async ({ runInlineTest }, testInfo) => {expect(result.report.suites[0].specs[1].tests[0].results[0].parallelIndex).toBe(1);expect(result.report.suites[0].specs[2].tests[0].results[0].parallelIndex).toBe(1);});--test('attaches error context', async ({ runInlineTest }) => {- const result = await runInlineTest({- 'playwright.config.ts': `- export default { use: { _optionErrorContext: { format: 'json' } } };- `,- 'a.test.js': `- const { test, expect } = require('@playwright/test');- test('one', async ({ page }, testInfo) => {- await page.setContent('<button>Click me</button>');- throw new Error('kaboom');- });- `,- }, { reporter: 'json' });-- const errorContext = result.report.suites[0].specs[0].tests[0].results[0].attachments.find(a => a.name === 'error-context');- expect(errorContext).toBeDefined();- expect(errorContext!.contentType).toBe('application/json');- const json = JSON.parse(Buffer.from(errorContext!.body, 'base64').toString('utf-8'));- expect(json).toEqual({- pageSnapshot: expect.any(String),- });-});