Skip to content

Commit

Permalink
test: fix for older pw versions
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Dec 8, 2024
1 parent cf9a99b commit 86878ad
Showing 1 changed file with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,36 @@ import { normalize } from 'node:path';
import { expect } from '@playwright/test';
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
const pwVersion = getPackageVersion('@playwright/test');
const hasDownloadTrace = pwVersion >= '1.42.0';

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()).toContainText(
[
`Hook "BeforeAll hook" failed: ${normalize('features/error-in-before-all/steps.ts')}:`, // prettier-ignore
'GivenAction 1',
hasDownloadTrace ? 'Download trace' : '',
].filter(Boolean),
);
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()).toContainText(
[
`Hook "BeforeAll hook" failed: ${normalize('features/error-in-before-all/steps.ts')}:`, // prettier-ignore
'GivenAction 2',
hasDownloadTrace ? 'Download trace' : '',
].filter(Boolean),
);
await expect(scenario.getSteps('failed')).toHaveCount(1);
await expect(scenario.getSteps('skipped')).toHaveCount(1);
await expect(scenario.getErrors()).toContainText([`expect(true).toEqual(false)`]);
Expand All @@ -32,11 +42,13 @@ 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()).toContainText(
[
`Hook "my hook" failed: ${normalize('features/error-in-before-all/steps.ts')}:`, // prettier-ignore
'GivenAction 1',
hasDownloadTrace ? 'Download trace' : '',
].filter(Boolean),
);
await expect(scenario.getSteps('failed')).toHaveCount(1);
await expect(scenario.getSteps('skipped')).toHaveCount(1);
await expect(scenario.getErrors()).toContainText([`expect(true).toEqual(false)`]);
Expand Down

0 comments on commit 86878ad

Please sign in to comment.