Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support fixtures #56

Merged
merged 4 commits into from
Jan 24, 2024
Merged

feat: support fixtures #56

merged 4 commits into from
Jan 24, 2024

Conversation

SebastianSedzik
Copy link
Owner

@SebastianSedzik SebastianSedzik commented Jan 23, 2024

Description

Add support for custom playwright fixtures in beforeAll, beforeEach, test, afterAll and afterEach decorators, by introducing extend method.

The extend<T>(customFixture) method generates decorators with access to custom fixture.

import { test as base } from 'playwright';
import { suite, test, extend } from 'playwright-decorators';

// #1 Create fixture type
type UserFixture = {
    user: {
      firstName: string;
      lastName: string;
    }
}

// #2 Create user fixture
const withUser = base.extend<UserFixture>({
    user: async ({}, use) => {
        await use({
            firstName: 'John',
            lastName: 'Doe'
        })
    }
})

// #3 Generate afterAll, afterEach, test, beforeAll, beforeEach decorators with access to the user fixture
const {
    afterAll,
    afterEach,
    test,
    beforeAll,
    beforeEach,
} = extend<UserFixture>(withUser);

// #4 Use decorators
@suite()
class MyTestSuite {
    @beforeAll()
    async beforeAll({ user }: TestArgs<UserFixture>) { // have access to user fixture
        // ...
    }

    @test()
    async test({ user }: TestArgs<UserFixture>) { // have access to user fixture
        // ...
    }
}

Copy link

changeset-bot bot commented Jan 23, 2024

🦋 Changeset detected

Latest commit: 8fa9ea3

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@SebastianSedzik SebastianSedzik merged commit 3a44870 into master Jan 24, 2024
4 checks passed
@SebastianSedzik SebastianSedzik deleted the support-fixtures branch January 24, 2024 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant