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
fix(test-runner): attachments push enumerable property (#37814)
Vladyslav Tkachenko4f9ba4b74e7c
diff --git a/packages/playwright/src/worker/testInfo.ts b/packages/playwright/src/worker/testInfo.tsindex c007255bcc..27ad9cc914 100644--- a/packages/playwright/src/worker/testInfo.ts+++ b/packages/playwright/src/worker/testInfo.ts@@ -214,11 +214,17 @@ export class TestInfoImpl implements TestInfo {})();this._attachmentsPush = this.attachments.push.bind(this.attachments);- this.attachments.push = (...attachments: TestInfo['attachments']) => {+ const attachmentsPush = (...attachments: TestInfo['attachments']) => {for (const a of attachments)this._attach(a, this._parentStep()?.stepId);return this.attachments.length;};+ Object.defineProperty(this.attachments, 'push', {+ value: attachmentsPush,+ writable: true,+ enumerable: false,+ configurable: true+ });this._tracing = new TestTracing(this, workerParams.artifactsDir);diff --git a/tests/playwright-test/reporter.spec.ts b/tests/playwright-test/reporter.spec.tsindex 9a04c246d9..358368a240 100644--- a/tests/playwright-test/reporter.spec.ts+++ b/tests/playwright-test/reporter.spec.ts@@ -674,6 +674,32 @@ test('should report annotations from test declaration', async ({ runInlineTest }]);});+test('attachments.push should not be enumerable to allow toEqual comparisons', async ({ runInlineTest }) => {+ const result = await runInlineTest({+ 'a.spec.js': `+ import { test, expect } from '@playwright/test';+ test('test.info().attachments.push should not be enumerable', async ({}) => {++ const attachments = test.info().attachments;++ const descriptor = Object.getOwnPropertyDescriptor(attachments, 'push');+ expect(descriptor).toBeTruthy();+ expect(descriptor.enumerable).toBe(false);++ expect(Object.keys(attachments)).not.toContain('push');++ await test.info().attach('file1', { body: 'content1', contentType: 'text/plain' });+ await test.info().attach('file2', { body: 'content2', contentType: 'text/plain' });++ const keys = Object.keys(attachments);+ expect(keys.every(k => !isNaN(Number(k)))).toBe(true);+ });+ `,+ });+ expect(result.exitCode).toBe(0);+ expect(result.passed).toBe(1);+});+test('tests skipped in serial mode receive onTestBegin/onTestEnd', async ({ runInlineTest }) => {test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/28321' });