Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,21 +239,11 @@ All of them are available globally in each Jest test. If you are using ESLint an

## Debug mode

Debugging tests can be hard sometimes and it is very useful to be able to pause tests in order to inspect the browser. There are two ways to put your tests in debug mode:

- Playwright give you [ability](https://playwright.dev/docs/debug/#run-in-debug-mode) to configure the browser for debugging with the `PWDEBUG` environment variable. It will launch the browser in headful mode and disables playwright timeout:
Playwright give you [ability](https://playwright.dev/docs/debug/#run-in-debug-mode) to configure the browser for debugging with the `PWDEBUG` environment variable. It will launch the browser in headful mode, disables playwright timeout and **Jest** won't timeout anymore.:
```js
PWDEBUG=1 jest
```

- Jest Playwright exposes a method `jestPlaywright.debug()` that suspends test execution and gives you opportunity to see what's going on in the browser.

```js
await jestPlaywright.debug()
```

In these cases **Jest** won't timeout anymore.

## Reset helper functions

### Reset current page
Expand Down
52 changes: 0 additions & 52 deletions src/PlaywrightEnvironment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable no-console, @typescript-eslint/no-unused-vars */
import type { Event, State } from 'jest-circus'
import type {
Browser,
BrowserContext,
Expand All @@ -20,7 +19,6 @@ import type {
import {
CHROMIUM,
CONFIG_ENVIRONMENT_NAME,
DEBUG_TIMEOUT,
DEFAULT_CONFIG,
FIREFOX,
IMPORT_KIND_PLAYWRIGHT,
Expand All @@ -42,12 +40,6 @@ const handleError = (error: Error): void => {
process.emit('uncaughtException', error)
}

const KEYS = {
CONTROL_C: '\u0003',
CONTROL_D: '\u0004',
ENTER: '\r',
}

const getBrowserPerProcess = async (
playwrightInstance: GenericBrowser,
browserType: BrowserType,
Expand Down Expand Up @@ -351,55 +343,11 @@ export const getPlaywrightEnv = (basicEnv = 'node'): unknown => {
)
this.global.page = await this._setNewPageInstance()
},
debug: async (): Promise<void> => {
// Run a debugger (in case Playwright has been launched with `{ devtools: true }`)
await this.global.page.evaluate(() => {
// eslint-disable-next-line no-debugger
debugger
})
// eslint-disable-next-line no-console
console.log('\n\n🕵️‍ Code is paused, press enter to resume')
// Run an infinite promise
return new Promise((resolve) => {
const { stdin } = process
const listening = stdin.listenerCount('data') > 0
const onKeyPress = (key: string): void => {
if (Object.values(KEYS).includes(key)) {
stdin.removeListener('data', onKeyPress)
if (!listening) {
if (stdin.isTTY) {
stdin.setRawMode(false)
}
stdin.pause()
}
resolve()
}
}
if (!listening) {
if (stdin.isTTY) {
stdin.setRawMode(true)
}
stdin.resume()
stdin.setEncoding('utf8')
}
stdin.on('data', onKeyPress)
})
},
saveCoverage: async (page: Page): Promise<void> =>
saveCoverageOnPage(page, collectCoverage),
}
}

async handleTestEvent(event: Event, state: State): Promise<void> {
// Hack to set testTimeout for jestPlaywright debugging
if (
event.name === 'add_test' &&
event.fn?.toString().includes('jestPlaywright.debug()')
) {
state.testTimeout = DEBUG_TIMEOUT
}
}

async teardown(): Promise<void> {
const { browser, context, page } = this.global
const { collectCoverage } = this._jestPlaywrightConfig
Expand Down