From 13a9528a13082ff2438122ed44c1102b566dce96 Mon Sep 17 00:00:00 2001 From: Vitaliy Potapov Date: Sun, 8 Dec 2024 11:38:39 +0400 Subject: [PATCH] test: add reporter test for error in before all --- .../specs/error-in-before-all.test.ts | 44 +++++++++++++++++++ .../error-in-before-all/anonymous.feature | 8 ++++ .../features/error-in-before-all/fixtures.ts | 24 ++++++++++ .../error-in-before-all/named.feature | 5 +++ .../error-in-before-all/sample.feature | 3 -- .../features/error-in-before-all/steps.ts | 13 ++++++ 6 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 test/reporter-cucumber-html/check-report/specs/error-in-before-all.test.ts create mode 100644 test/reporter-cucumber-html/features/error-in-before-all/anonymous.feature create mode 100644 test/reporter-cucumber-html/features/error-in-before-all/fixtures.ts create mode 100644 test/reporter-cucumber-html/features/error-in-before-all/named.feature delete mode 100644 test/reporter-cucumber-html/features/error-in-before-all/sample.feature create mode 100644 test/reporter-cucumber-html/features/error-in-before-all/steps.ts diff --git a/test/reporter-cucumber-html/check-report/specs/error-in-before-all.test.ts b/test/reporter-cucumber-html/check-report/specs/error-in-before-all.test.ts new file mode 100644 index 00000000..2d8d16b2 --- /dev/null +++ b/test/reporter-cucumber-html/check-report/specs/error-in-before-all.test.ts @@ -0,0 +1,44 @@ +import { normalize } from 'node:path'; +import { expect } from '@playwright/test'; +import { test } from '../fixtures'; + +test.describe('error in anonymous before all hook', () => { + test.use({ featureUri: 'error-in-before-all/anonymous.feature' }); + + test('scenario 1', async ({ scenario }) => { + await expect(scenario.getSteps()).toContainText([ + `Hook "BeforeAll hook" failed: ${normalize('features/error-in-before-all/steps.ts')}:`, // prettier-ignore + 'GivenAction 1', + 'Download trace', + ]); + await expect(scenario.getSteps('failed')).toHaveCount(1); + await expect(scenario.getSteps('skipped')).toHaveCount(1); + await expect(scenario.getErrors()).toContainText([`expect(true).toEqual(false)`]); + }); + + test('scenario 2', async ({ scenario }) => { + await expect(scenario.getSteps()).toContainText([ + `Hook "BeforeAll hook" failed: ${normalize('features/error-in-before-all/steps.ts')}:`, // prettier-ignore + 'GivenAction 2', + 'Download trace', + ]); + await expect(scenario.getSteps('failed')).toHaveCount(1); + await expect(scenario.getSteps('skipped')).toHaveCount(1); + await expect(scenario.getErrors()).toContainText([`expect(true).toEqual(false)`]); + }); +}); + +test.describe('error in named before all hook', () => { + test.use({ featureUri: 'error-in-before-all/named.feature' }); + + test('scenario 1', async ({ scenario }) => { + await expect(scenario.getSteps()).toContainText([ + `Hook "my hook" failed: ${normalize('features/error-in-before-all/steps.ts')}:`, // prettier-ignore + 'GivenAction 1', + 'Download trace', + ]); + await expect(scenario.getSteps('failed')).toHaveCount(1); + await expect(scenario.getSteps('skipped')).toHaveCount(1); + await expect(scenario.getErrors()).toContainText([`expect(true).toEqual(false)`]); + }); +}); diff --git a/test/reporter-cucumber-html/features/error-in-before-all/anonymous.feature b/test/reporter-cucumber-html/features/error-in-before-all/anonymous.feature new file mode 100644 index 00000000..1c15863b --- /dev/null +++ b/test/reporter-cucumber-html/features/error-in-before-all/anonymous.feature @@ -0,0 +1,8 @@ +@failing-anonymous-before-all-hook +Feature: anonymous before-all hook + + Scenario: scenario 1 + Given Action 1 + + Scenario: scenario 2 + Given Action 2 diff --git a/test/reporter-cucumber-html/features/error-in-before-all/fixtures.ts b/test/reporter-cucumber-html/features/error-in-before-all/fixtures.ts new file mode 100644 index 00000000..6eb68936 --- /dev/null +++ b/test/reporter-cucumber-html/features/error-in-before-all/fixtures.ts @@ -0,0 +1,24 @@ +import { test as base } from 'playwright-bdd'; + +export const test = base.extend< + object, + { + workerFixtureWithErrorInSetup: void; + workerFixtureWithTimeoutInSetup: void; + } +>({ + workerFixtureWithErrorInSetup: [ + async ({}, use) => { + throw new Error('error in worker fixture setup'); + await use(); + }, + { scope: 'worker' }, + ], + workerFixtureWithTimeoutInSetup: [ + async ({}, use, workerInfo) => { + await new Promise((r) => setTimeout(r, workerInfo.project.timeout + 100)); + await use(); + }, + { scope: 'worker' }, + ], +}); diff --git a/test/reporter-cucumber-html/features/error-in-before-all/named.feature b/test/reporter-cucumber-html/features/error-in-before-all/named.feature new file mode 100644 index 00000000..5aad90d5 --- /dev/null +++ b/test/reporter-cucumber-html/features/error-in-before-all/named.feature @@ -0,0 +1,5 @@ +@failing-named-before-all-hook +Feature: named before-all hook + + Scenario: scenario 1 + Given Action 1 diff --git a/test/reporter-cucumber-html/features/error-in-before-all/sample.feature b/test/reporter-cucumber-html/features/error-in-before-all/sample.feature deleted file mode 100644 index 89df1568..00000000 --- a/test/reporter-cucumber-html/features/error-in-before-all/sample.feature +++ /dev/null @@ -1,3 +0,0 @@ -Feature: error-in-before-all - - diff --git a/test/reporter-cucumber-html/features/error-in-before-all/steps.ts b/test/reporter-cucumber-html/features/error-in-before-all/steps.ts new file mode 100644 index 00000000..e865d2ac --- /dev/null +++ b/test/reporter-cucumber-html/features/error-in-before-all/steps.ts @@ -0,0 +1,13 @@ +import { expect } from '@playwright/test'; +import { createBdd } from 'playwright-bdd'; +import { test } from './fixtures'; + +const { BeforeAll } = createBdd(test); + +BeforeAll({ tags: '@failing-anonymous-before-all-hook' }, async () => { + expect(true).toEqual(false); +}); + +BeforeAll({ name: 'my hook', tags: '@failing-named-before-all-hook' }, async () => { + expect(true).toEqual(false); +});