Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit 8ce19bc

Browse files
authored
Add documentation jest circus (#106)
* Add documentation for jest-circus
1 parent 0be92af commit 8ce19bc

File tree

3 files changed

+1023
-3271
lines changed

3 files changed

+1023
-3271
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,49 @@ If there is no defined browsers in config it will run tests for chromium browser
187187
"test:parallel": "jest-playwright --parallel"
188188
```
189189

190+
## Usage with [jest-circus](https://github.com/facebook/jest/tree/master/packages/jest-circus)
191+
192+
You can use **jest-playwright** with **jest-circus** runner for taking screenshots during test failures for example:
193+
194+
**jest.config.json**
195+
196+
```json
197+
"testRunner": "jest-circus/runner",
198+
"testEnvironment": "./CustomEnvironment.js"
199+
```
200+
201+
**CustomEnvironment.js**
202+
203+
```js
204+
const PlaywrightEnvironment = require('jest-playwright-preset/lib/PlaywrightEnvironment')
205+
.default
206+
207+
class CustomEnvironment extends PlaywrightEnvironment {
208+
async setup() {
209+
await super.setup()
210+
// Your setup
211+
}
212+
213+
async teardown() {
214+
// Your teardown
215+
await super.teardown()
216+
}
217+
218+
async handleTestEvent(event) {
219+
if (event.name === 'test_done' && event.test.errors.length > 0) {
220+
const parentName = event.test.parent.name.replace(/\W/g, '-')
221+
const specName = event.test.name.replace(/\W/g, '-')
222+
223+
await this.global.page.screenshot({
224+
path: `screenshots/${parentName}_${specName}.png`,
225+
})
226+
}
227+
}
228+
}
229+
230+
module.exports = CustomEnvironment
231+
```
232+
190233
## Usage with Typescript
191234

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

0 commit comments

Comments
 (0)