Skip to content

Commit

Permalink
test: prepare for after-all html report
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Dec 8, 2024
1 parent 9bef012 commit 5d78c29
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { test } from '../fixtures';

// All these tests are skipped because they are marked as passed in Cucumber html report.
// It's because afterAll hooks run in worker fixture teardown phase that is not related to any test.
// In case of error, this error is reported via reporter.onError, not in test results.
//
// It would be better to run afterAll hooks inside test.afterAll(),
// but it's will work incorrectly if single afterAll hook is tagged to several features,
// because it will be run several times.

test.describe.skip('error in anonymous after all hook', () => {
test.use({ featureUri: 'error-in-after-all/anonymous.feature' });

test('scenario 1', async () => {});
test('scenario 2', async () => {});
});

test.describe.skip('error in named after all hook', () => {
test.use({ featureUri: 'error-in-after-all/named.feature' });

test('scenario 1', async () => {});
});

test.describe.skip('error in worker fixture teardown', () => {
test.use({ featureUri: 'error-in-after-all/fixture.feature' });

test('scenario 1', async () => {});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { test } from '../fixtures';

import { getPackageVersion } from '../../../../src/utils';

// Download trace appears in the report in case of error in before all hook since 1.42
// 'Download trace' appears in the report in case of error in before all hook since 1.42
const pwVersion = getPackageVersion('@playwright/test');
const hasDownloadTrace = pwVersion >= '1.42.0';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@failing-anonymous-after-all-hook
Feature: error in anonymous after-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,5 @@
Feature: error in worker fixture teardown (after-all)

Scenario: scenario 1
Given Action 1
Given step that uses workerFixtureWithErrorInTeardown
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,
{
workerFixtureWithErrorInTeardown: void;
workerFixtureWithTimeoutInTeardown: void;
}
>({
workerFixtureWithErrorInTeardown: [
async ({}, use) => {
await use();
throw new Error('error in worker fixture setup');
},
{ scope: 'worker' },
],
workerFixtureWithTimeoutInTeardown: [
async ({}, use, workerInfo) => {
await use();
await new Promise((r) => setTimeout(r, workerInfo.project.timeout + 100));
},
{ scope: 'worker' },
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@failing-named-after-all-hook
Feature: error in named after-all hook

Scenario: scenario 1
Given Action 1
20 changes: 20 additions & 0 deletions test/reporter-cucumber-html/features/error-in-after-all/steps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expect } from '@playwright/test';
import { createBdd } from 'playwright-bdd';
import { test } from './fixtures';

const { Given, AfterAll } = createBdd(test);

AfterAll({ tags: '@failing-anonymous-after-all-hook' }, async () => {
expect(true).toEqual(false);
});

AfterAll({ name: 'my hook', tags: '@failing-named-after-all-hook' }, async () => {
expect(true).toEqual(false);
});

Given(
'step that uses workerFixtureWithErrorInTeardown',
async ({ workerFixtureWithErrorInTeardown }) => {
return workerFixtureWithErrorInTeardown;
},
);

0 comments on commit 5d78c29

Please sign in to comment.