Skip to content

Commit

Permalink
fix worker hooks and hooks-tags test
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Oct 24, 2024
1 parent 63ed127 commit e2dfdc8
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/run/bddFixtures/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ export const test = base.extend<BddFixturesTest>({
// Unused fixtures below are important for lazy initialization only on bdd projects
// See: https://github.com/vitalets/playwright-bdd/issues/166
Given: [
({ $bddContext, $applySpecialTags }, use) => use(createStepInvoker($bddContext)),
// todo: $beforeAll, $afterAll should go away
({ $bddContext, $applySpecialTags, $beforeAll, $afterAll }, use) =>
use(createStepInvoker($bddContext)),
fixtureOptions,
],
// All invoke step fixtures use the same Given fixture, b/c we get keyword from step meta (by index)
Expand Down
4 changes: 2 additions & 2 deletions test/hooks-tags/features/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* eslint-disable @typescript-eslint/no-unused-vars */

import { expect } from '@playwright/test';
import { Before, After, AfterAll } from './fixtures';
import { track, calls } from './track';

const logger = console;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Before('@bar', async function ({ $testInfo, $tags, fixtureForBar }) {
track(`Before @bar ${$testInfo.title}`);
expect($tags).toEqual(['@foo', '@bar']);
});

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Before({ tags: '@foo and not @bar' }, async ({ $testInfo, fixtureForFoo }) => {
track(`Before @foo and not @bar ${$testInfo.title}`);
});
Expand Down
4 changes: 4 additions & 0 deletions test/hooks-tags/features/sample2.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Feature: sample

Scenario: scenario 3
Given step in sample2
6 changes: 6 additions & 0 deletions test/hooks-tags/features/steps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { Given } from './fixtures';
import { track } from './track';

const logger = console;

Given('State {int}', async ({ $testInfo }) => {
track(`Step ${$testInfo.title}`);
});

Given('step in sample2', async () => {
logger.log(`step in sample2`);
});
29 changes: 29 additions & 0 deletions test/hooks-tags/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test(`${testDir.name} (run all tests)`, () => {

expect(stdout).toContain('setup fixture for foo');
expect(stdout).toContain('setup fixture for bar');
expect(stdout).toContain('step in sample2');

expectHookCalls(stdout, [
'Before @bar scenario 1',
Expand Down Expand Up @@ -51,6 +52,7 @@ test(`${testDir.name} (gen not bar)`, () => {

expect(stdout).toContain('setup fixture for foo');
expect(stdout).not.toContain('setup fixture for bar');
expect(stdout).toContain('step in sample2');

expectHookCalls(stdout, [
'Before @foo and not @bar scenario 2', // prettier-ignore
Expand Down Expand Up @@ -91,6 +93,7 @@ test(`${testDir.name} (run not bar)`, { skip: !pwSupportsTags }, () => {
// We can't know beforehand, which will it be filtered with PW tags in runtime.
// Looks like a minor issue.
expect(stdout).toContain('setup fixture for bar');
expect(stdout).toContain('step in sample2');

expectHookCalls(stdout, [
'Before @foo and not @bar scenario 2', // prettier-ignore
Expand All @@ -99,6 +102,32 @@ test(`${testDir.name} (run not bar)`, { skip: !pwSupportsTags }, () => {
]);
});

test(`${testDir.name} (gen not foo)`, () => {
const stdout = execPlaywrightTest(
testDir.name,
`${BDDGEN_CMD} --tags "not @foo" && ${PLAYWRIGHT_CMD}`,
);

expect(stdout).toContain('step in sample2');

expect(stdout).not.toContain('setup fixture for foo');
expect(stdout).not.toContain('setup fixture for bar');
expectHookCalls(stdout, []);
});

test(`${testDir.name} (run not foo)`, () => {
const stdout = execPlaywrightTest(
testDir.name,
`${BDDGEN_CMD} && ${PLAYWRIGHT_CMD} --grep-invert "@foo"`,
);

expect(stdout).toContain('step in sample2');

expect(stdout).not.toContain('setup fixture for foo');
expect(stdout).not.toContain('setup fixture for bar');
expectHookCalls(stdout, []);
});

function expectHookCalls(stdout, hookCalls) {
expect(stdout).toContain(['Start', ...hookCalls, 'End'].join('\n'));
}

0 comments on commit e2dfdc8

Please sign in to comment.