From 218955c1552fd95cf8630caa1b271e6dd1e44b3d Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Wed, 23 Aug 2023 08:40:12 -0700 Subject: [PATCH] fix(test runner): make sure static annotations are reported for skipped tests (#26634) Fixes #26397. --- .../playwright-test/src/common/suiteUtils.ts | 1 + packages/playwright-test/src/common/test.ts | 2 ++ .../playwright-test/src/runner/dispatcher.ts | 1 - tests/playwright-test/test-modifiers.spec.ts | 27 +++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/playwright-test/src/common/suiteUtils.ts b/packages/playwright-test/src/common/suiteUtils.ts index da3714ba7f..7994c10e04 100644 --- a/packages/playwright-test/src/common/suiteUtils.ts +++ b/packages/playwright-test/src/common/suiteUtils.ts @@ -68,6 +68,7 @@ export function bindFileSuiteToProject(project: FullProjectInternal, suite: Suit } test.retries = inheritedRetries ?? project.project.retries; test.timeout = inheritedTimeout ?? project.project.timeout; + test.annotations = [...test._staticAnnotations]; // Skip annotations imply skipped expectedStatus. if (test._staticAnnotations.some(a => a.type === 'skip' || a.type === 'fixme')) diff --git a/packages/playwright-test/src/common/test.ts b/packages/playwright-test/src/common/test.ts index aadcc89781..a1afee5b08 100644 --- a/packages/playwright-test/src/common/test.ts +++ b/packages/playwright-test/src/common/test.ts @@ -292,6 +292,7 @@ export class TestCase extends Base implements reporterTypes.TestCase { poolDigest: this._poolDigest, workerHash: this._workerHash, staticAnnotations: this._staticAnnotations.slice(), + annotations: this.annotations.slice(), projectId: this._projectId, }; } @@ -307,6 +308,7 @@ export class TestCase extends Base implements reporterTypes.TestCase { test._poolDigest = data.poolDigest; test._workerHash = data.workerHash; test._staticAnnotations = data.staticAnnotations; + test.annotations = data.annotations; test._projectId = data.projectId; return test; } diff --git a/packages/playwright-test/src/runner/dispatcher.ts b/packages/playwright-test/src/runner/dispatcher.ts index dcaf0f6289..42b8a2fa55 100644 --- a/packages/playwright-test/src/runner/dispatcher.ts +++ b/packages/playwright-test/src/runner/dispatcher.ts @@ -76,7 +76,6 @@ export class Dispatcher { const result = test._appendTestResult(); result.status = 'skipped'; this._reporter.onTestBegin(test, result); - test.annotations = [...test._staticAnnotations]; this._reportTestEnd(test, result); } this._queue.shift(); diff --git a/tests/playwright-test/test-modifiers.spec.ts b/tests/playwright-test/test-modifiers.spec.ts index c5ed51a488..ce9a1aff9a 100644 --- a/tests/playwright-test/test-modifiers.spec.ts +++ b/tests/playwright-test/test-modifiers.spec.ts @@ -619,3 +619,30 @@ test('should skip tests if beforeEach has skip', async ({ runInlineTest }) => { expectTest('no marker', 'skipped', 'skipped', ['skip']); expect(result.output).not.toContain('skip-me'); }); + +test('static modifiers should be added in serial mode', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'a.test.ts': ` + import { test } from '@playwright/test'; + + test.describe.configure({ mode: 'serial' }); + test('failed', async ({}) => { + test.slow(); + throw new Error('blocking error'); + }); + test.fixme('fixmed', async ({}) => { + }); + test.skip('skipped', async ({}) => { + }); + test('ignored', async ({}) => { + }); + `, + }); + expect(result.exitCode).toBe(1); + expect(result.passed).toBe(0); + expect(result.skipped).toBe(3); + expect(result.report.suites[0].specs[0].tests[0].annotations).toEqual([{ type: 'slow' }]); + expect(result.report.suites[0].specs[1].tests[0].annotations).toEqual([{ type: 'fixme' }]); + expect(result.report.suites[0].specs[2].tests[0].annotations).toEqual([{ type: 'skip' }]); + expect(result.report.suites[0].specs[3].tests[0].annotations).toEqual([]); +});