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(reporter): properly record result annotations when all tests are skipped (#38210)
Adam Gastineauaab804e1f52c
diff --git a/packages/html-reporter/src/testCaseView.tsx b/packages/html-reporter/src/testCaseView.tsxindex 75a8e1c742..22e5c146f8 100644--- a/packages/html-reporter/src/testCaseView.tsx+++ b/packages/html-reporter/src/testCaseView.tsx@@ -68,6 +68,7 @@ export const TestCaseView: React.FC<{<div className='test-case-duration'>{msToString(test.duration)}</div></div><ProjectAndTagLabelsView style={{ marginLeft: '6px' }} projectNames={projectNames} activeProjectName={test.projectName} otherLabels={test.tags} />+ {/* If there are no results, display test annotations. Otherwise test annotations will be displayed alongside runtime annotations in individual result pane */}{test.results.length === 0 && visibleTestAnnotations.length !== 0 && <AutoChip header='Annotations' dataTestId='test-case-annotations'>{visibleTestAnnotations.map((annotation, index) => <TestCaseAnnotationView key={index} annotation={annotation} />)}</AutoChip>}diff --git a/packages/playwright/src/runner/dispatcher.ts b/packages/playwright/src/runner/dispatcher.tsindex d2e122fa53..358f639ac0 100644--- a/packages/playwright/src/runner/dispatcher.ts+++ b/packages/playwright/src/runner/dispatcher.ts@@ -619,6 +619,8 @@ class JobDispatcher {const result = test._appendTestResult();this._reporter.onTestBegin?.(test, result);result.status = 'skipped';+ // This must mirror _onTestEnd() above+ result.annotations = [...test.annotations];this._reportTestEnd(test, result);}return true;diff --git a/tests/playwright-test/reporter.spec.ts b/tests/playwright-test/reporter.spec.tsindex 358368a240..b7e8dc9638 100644--- a/tests/playwright-test/reporter.spec.ts+++ b/tests/playwright-test/reporter.spec.ts@@ -831,3 +831,58 @@ test('attachments are reported in onStepEnd', { annotation: { type: 'issue', des'[hook] After Hooks: 2 attachments in result',]);});++test('should have static annotations on result when all tests are skipped', async ({ runInlineTest }) => {+ class TestReporter implements Reporter {+ onTestEnd(test: TestCase, result: TestResult): void {+ for (const annotation of result.annotations)+ console.log(`%%annotation: ${annotation.type} ${annotation.description || ''}`);+ }+ }++ const result = await runInlineTest({+ 'reporter.ts': `module.exports = ${TestReporter.toString()}`,+ 'playwright.config.ts': `module.exports = { reporter: './reporter' };`,+ 'a.spec.ts': `+ import { test } from '@playwright/test';+ test.skip('test', {+ annotation: [{ type: 'foo', description: 'desc' }, { type: 'bar' }],+ }, async () => {});+ `,+ }, { 'reporter': '', 'workers': 1 });++ expect(result.outputLines).toEqual([+ 'annotation: foo desc',+ 'annotation: bar',+ 'annotation: skip',+ ]);++ const resultMany = await runInlineTest({+ 'reporter.ts': `module.exports = ${TestReporter.toString()}`,+ 'playwright.config.ts': `module.exports = { reporter: './reporter' };`,+ 'a.spec.ts': `+ import { test } from '@playwright/test';+ test.skip('test', {+ annotation: [{ type: 'foo', description: 'desc' }, { type: 'bar' }],+ }, async () => {});++ test.skip('test2', {+ annotation: [{ type: 'foobar', description: 'another' }],+ }, async () => {});++ test.skip('test3', {+ annotation: [{ type: 'warning', description: 'one more' }],+ }, async () => {});+ `,+ }, { 'reporter': '', 'workers': 1 });++ expect(resultMany.outputLines).toEqual([+ 'annotation: foo desc',+ 'annotation: bar',+ 'annotation: skip',+ 'annotation: foobar another',+ 'annotation: skip',+ 'annotation: warning one more',+ 'annotation: skip',+ ]);+});