Skip to content

Commit

Permalink
test: add reporter test for error in before all
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Dec 8, 2024
1 parent 5dba3b1 commit 13a9528
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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)`]);
});
});
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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' },
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@failing-named-before-all-hook
Feature: named before-all hook

Scenario: scenario 1
Given Action 1

This file was deleted.

13 changes: 13 additions & 0 deletions test/reporter-cucumber-html/features/error-in-before-all/steps.ts
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit 13a9528

Please sign in to comment.