diff --git a/.changeset/slimy-spiders-cover.md b/.changeset/slimy-spiders-cover.md deleted file mode 100644 index 3f74aff..0000000 --- a/.changeset/slimy-spiders-cover.md +++ /dev/null @@ -1,53 +0,0 @@ ---- -"playwright-decorators": minor ---- - -Add support for fixtures - -This release introduce a new method `extend(customFixture)` that allows to create decorators (`afterAll`, `afterEach`, `test`, `beforeAll`, `beforeEach`) with access to custom fixtures. - -```ts -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({ - 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(withUser); - -// #4 Use decorators -@suite() -class MyTestSuite { - @beforeAll() - async beforeAll({ user }: TestArgs) { // have access to user fixture - // ... - } - - @test() - async test({ user }: TestArgs) { // have access to user fixture - // ... - } -} -``` diff --git a/CHANGELOG.md b/CHANGELOG.md index d027f0c..f289772 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,59 @@ ### Changelog +## 0.15.0 + +### Minor Changes + +- [#56](https://github.com/SebastianSedzik/playwright-decorators/pull/56) [`3a44870`](https://github.com/SebastianSedzik/playwright-decorators/commit/3a44870c0ef5f420744d944549fb0491cb1cb199) Thanks [@SebastianSedzik](https://github.com/SebastianSedzik)! - Add support for fixtures + + This release introduce a new method `extend(customFixture)` that allows to create decorators (`afterAll`, `afterEach`, `test`, `beforeAll`, `beforeEach`) with access to custom fixtures. + + ```ts + import { test as base } from 'playwright'; + import { suite, test, extend } from 'playwright-decorators'; + + // #1 Create fixture type + type UserFixture = { + + firstName: string; + lastName: string; + } + } + + // #2 Create user fixture + const withUser = base.extend({ + ({}, 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(withUser); + + // #4 Use decorators + @suite() + class MyTestSuite { + @beforeAll() + async beforeAll({ user }: TestArgs) { // have access to user fixture + // ... + } + + @test() + async test({ user }: TestArgs) { // have access to user fixture + // ... + } + } + ``` + ## 0.14.3 ### Patch Changes diff --git a/package.json b/package.json index 134903a..f7b6313 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "playwright-decorators", - "version": "0.14.3", + "version": "0.15.0", "description": "Decorators for writing Playwright based tests.", "main": "./dist/index.js", "types": "./dist/index.d.ts",