Skip to content

Commit dc4096b

Browse files
authored
Refactoring jest-playwright (#113)
* Creating PlaywrightRunner * Add types for browsers * Update dependencies, fix jest-environment-node peer dep * Rewrite selectors register logic * Using jest-circus as default testRunner, add jest-playwright-runner to jest-preset.json * Some PlaywrightEnvironment fixes, fix utils tests * Fix utils test for getPlaywrightInstance function * Remove unused SelectorType from utils * Replace browser with browsers, rollback to support passing browser param through process.env * Fix some utils functions * Fix testProcess * Support devices * Add devices to constants, support jest displayName * Case for empty devices * Fix some tests * Improve some tests * Remove jest-playwright bin * Update links in package.json * Fix typo and remove unused properties from types * Some logic changes * Fix displayName * Move back test for browserName * Some README fixes * Some README fixes * Refactoring getTests logic
1 parent 2dc517e commit dc4096b

15 files changed

+1723
-1548
lines changed

README.md

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Use Playwright in your tests:
5656
```
5757

5858
```js
59-
describe('Google', () => {
59+
describe('What is my browser', () => {
6060
beforeAll(async () => {
6161
await page.goto('https://whatismybrowser.com/')
6262
})
@@ -75,11 +75,11 @@ You can specify a `jest-playwright.config.js` at the root of the project or defi
7575
- `launchBrowserApp` <[object]> [All Playwright launch options](https://github.com/microsoft/playwright/blob/master/docs/api.md#browsertypelaunchoptions) can be specified in config. Since it is JavaScript, you can use all stuff you need, including environment.
7676
- `connectBrowserApp` <[object]> [All Playwright connect options](https://github.com/microsoft/playwright/blob/master/docs/api.md#browsertypeconnectoptions) can be specified in config.
7777
- `context` <[object]> [All Playwright context options](https://github.com/microsoft/playwright/blob/master/docs/api.md#browsernewcontextoptions) can be specified in config.
78-
- `browser` <[string]>. Define a [browser](https://github.com/microsoft/playwright/blob/master/docs/api.md#class-browsertype) to run tests into.
78+
- `browsers` <[string[]]>. Define a [browsers](https://github.com/microsoft/playwright/blob/master/docs/api.md#class-browsertype) to run tests into.
7979
- `chromium` Each test runs Chromium (default).
8080
- `firefox` Each test runs Firefox.
8181
- `webkit` Each test runs Webkit.
82-
- `device` <[string]>. Define a [device](https://github.com/microsoft/playwright/blob/master/docs/api.md#browsertypedevices) to run tests into. Actual list of devices can be found [here](https://github.com/Microsoft/playwright/blob/master/src/deviceDescriptors.ts)
82+
- `devices` <[string[]]>. Define a [devices](https://github.com/microsoft/playwright/blob/master/docs/api.md#browsertypedevices) to run tests into. Actual list of devices can be found [here](https://github.com/Microsoft/playwright/blob/master/src/deviceDescriptors.ts)
8383
- `exitOnPageError` <[boolean]> Exits process on any page error. Defaults to `true`.
8484
- `server` <[object]> [All `jest-dev-server` options](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-dev-server#options)
8585
- `selectors` <[array]>. Define [selector](https://github.com/microsoft/playwright/blob/v0.11.1/docs/api.md#class-selectors). Each selector must be an object with name and script properties.
@@ -143,50 +143,28 @@ There is [eslint-plugin-jest-playwright](https://github.com/mxschmitt/eslint-plu
143143

144144
## Unstable and experimental API
145145

146-
From version **0.0.7** you can run you tests for multiple browsers.
146+
You can run tests for multiple browsers and devices:
147147

148148
- You must have installed **playwright** package
149-
- You must define browser to test with your `jest-playwright.config.js`:
149+
- You must define browsers to test with your `jest-playwright.config.js`:
150150

151151
```javascript
152152
module.exports = {
153153
browsers: ["chromium", "webkit"],
154-
...
155-
}
156-
```
157-
158-
From version **0.0.13** you can run you tests for multiple devices.
159-
160-
```javascript
161-
module.exports = {
162154
devices: ["iPhone 6", "Pixel 2"],
163155
...
164156
}
165157
```
166158

167-
It will run your tests depending on you playwright package.
159+
It will run your tests for:
168160

169-
- If you are using specific playwright package, it will run test for this specific browser
170-
- With installed **playwright** package you can define browsers with config:
171-
172-
```javascript
173-
module.exports = {
174-
browsers: ["chromium", "firefox"],
175-
devices: ["iPhone 6", "Pixel 2"],
176-
...
177-
}
178-
```
161+
- **Chromium** browser and **iPhone 6** device;
162+
- **Chromium** browser and **Pixel 2** device;
163+
- **Webkit** browser and **iPhone 6** device;
164+
- **Webkit** browser and **Pixel 2** device;
179165

180166
If there is no defined browsers in config it will run tests for chromium browser.
181167

182-
[More details](https://github.com/mmarkelov/jest-playwright/pull/54#issuecomment-592514337)
183-
184-
- You must run your tests with **jest-playwright**
185-
186-
```json
187-
"test:parallel": "jest-playwright --parallel"
188-
```
189-
190168
## Usage with [jest-circus](https://github.com/facebook/jest/tree/master/packages/jest-circus)
191169

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

jest-preset.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"globalSetup": "jest-playwright-preset/setup.js",
33
"globalTeardown": "jest-playwright-preset/teardown.js",
44
"testEnvironment": "jest-playwright-preset",
5+
"runner": "jest-playwright-preset/runner.js",
6+
"testRunner": "jest-circus/runner",
57
"setupFilesAfterEnv": [
68
"expect-playwright"
79
]

jest.config.e2e.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
preset: 'ts-jest',
33
testEnvironment: './lib/PlaywrightEnvironment.js',
4+
runner: './runner.js',
45
testPathIgnorePatterns: ['/node_modules/', 'lib'],
56
testMatch: ['**/e2e/**/*.test.ts'],
67
}

0 commit comments

Comments
 (0)