Skip to content

Commit

Permalink
Add documentation jest circus (#106)
Browse files Browse the repository at this point in the history
* Add documentation for jest-circus
  • Loading branch information
mmarkelov committed Apr 10, 2020
1 parent 0be92af commit 8ce19bc
Show file tree
Hide file tree
Showing 3 changed files with 1,023 additions and 3,271 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,49 @@ If there is no defined browsers in config it will run tests for chromium browser
"test:parallel": "jest-playwright --parallel"
```

## Usage with [jest-circus](https://github.com/facebook/jest/tree/master/packages/jest-circus)

You can use **jest-playwright** with **jest-circus** runner for taking screenshots during test failures for example:

**jest.config.json**

```json
"testRunner": "jest-circus/runner",
"testEnvironment": "./CustomEnvironment.js"
```

**CustomEnvironment.js**

```js
const PlaywrightEnvironment = require('jest-playwright-preset/lib/PlaywrightEnvironment')
.default

class CustomEnvironment extends PlaywrightEnvironment {
async setup() {
await super.setup()
// Your setup
}

async teardown() {
// Your teardown
await super.teardown()
}

async handleTestEvent(event) {
if (event.name === 'test_done' && event.test.errors.length > 0) {
const parentName = event.test.parent.name.replace(/\W/g, '-')
const specName = event.test.name.replace(/\W/g, '-')

await this.global.page.screenshot({
path: `screenshots/${parentName}_${specName}.png`,
})
}
}
}

module.exports = CustomEnvironment
```

## Usage with Typescript

Example Jest configuration in combination with [ts-jest](https://github.com/kulshekhar/ts-jest):
Expand Down

0 comments on commit 8ce19bc

Please sign in to comment.