Skip to content
This repository was archived by the owner on Oct 17, 2024. It is now read-only.

Commit 29d1573

Browse files
authored
feat: update coverage example for new coverage integration and bumped (#8)
1 parent ba0ad37 commit 29d1573

File tree

13 files changed

+27
-68
lines changed

13 files changed

+27
-68
lines changed

basic-ts/jest-playwright.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// https://github.com/playwright-community/jest-playwright/#configuration
22
module.exports = {
33
browsers: ["chromium", "firefox", "webkit"],
4-
launchBrowserApp: {
4+
launchOptions: {
55
headless: true
66
}
77
}

basic-ts/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
"test": "jest"
99
},
1010
"devDependencies": {
11-
"@types/jest": "^25.2.3",
12-
"@types/node": "^14.0.5",
11+
"@types/jest": "^26.0.0",
12+
"@types/node": "^14.0.13",
1313
"jest": "^26.0.1",
14-
"jest-playwright-preset": "^0.2.2",
15-
"playwright": "^1.0.2",
16-
"ts-jest": "^26.0.0",
17-
"typescript": "^3.9.3"
14+
"jest-playwright-preset": "^1.0.0",
15+
"playwright": "^1.1.1",
16+
"ts-jest": "^26.1.1",
17+
"typescript": "^3.9.5"
1818
},
1919
"dependencies": {}
2020
}

basic/jest-playwright.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// https://github.com/playwright-community/jest-playwright/#configuration
22
module.exports = {
33
browsers: ["chromium", "firefox", "webkit"],
4-
launchBrowserApp: {
4+
launchOptions: {
55
headless: true
66
}
77
}

basic/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
},
1010
"devDependencies": {
1111
"jest": "^26.0.1",
12-
"jest-playwright-preset": "^0.2.2",
13-
"playwright": "^1.0.2"
12+
"jest-playwright-preset": "^1.0.0",
13+
"playwright": "^1.1.1"
1414
},
1515
"dependencies": {}
1616
}

create-react-app-coverage/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
# Jest create-react-app Playwright example with coverage
42

53
[![Coverage Status](https://coveralls.io/repos/github/playwright-community/playwright-jest-examples/badge.svg)](https://coveralls.io/github/playwright-community/playwright-jest-examples)

create-react-app-coverage/after.js

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// https://github.com/playwright-community/jest-playwright/#configuration
22
module.exports = {
33
browsers: ['chromium', 'firefox', 'webkit'],
4-
server: {
4+
serverOptions: {
55
command: `BROWSER=none npm start`,
66
port: 3000,
77
launchTimeout: 10000,
88
debug: true,
99
},
10-
launchBrowserApp: {
10+
launchOptions: {
1111
headless: true
12-
}
12+
},
13+
collectCoverage: true
1314
}

create-react-app-coverage/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
"babel-plugin-istanbul": "^6.0.0",
1111
"customize-cra": "^1.0.0",
1212
"jest": "^26.0.1",
13-
"jest-playwright-preset": "^0.2.5",
13+
"jest-playwright-preset": "^1.0.0",
1414
"nyc": "^15.1.0",
1515
"playwright": "^1.1.1",
1616
"react": "^16.13.1",
1717
"react-app-rewired": "^2.1.6",
1818
"react-dom": "^16.13.1",
1919
"react-scripts": "3.4.1",
20-
"ts-jest": "^26.1.0",
20+
"ts-jest": "^26.1.1",
2121
"typescript": "^3.9.5"
2222
},
2323
"scripts": {
2424
"start": "react-app-rewired start",
2525
"build": "react-app-rewired build",
26-
"test": "rm -rf .pw-cov && jest -c jest.config.js && node after.js && nyc report --reporter=lcovonly",
26+
"test": "jest -c jest.config.js && nyc report --reporter=lcovonly",
2727
"eject": "react-scripts eject"
2828
},
2929
"eslintConfig": {

create-react-app-coverage/src/App.test.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
1-
import fs from "fs";
2-
import { promisify } from 'util'
3-
import path from "path";
4-
5-
const fsWriteFile = promisify(fs.writeFile);
6-
7-
const COV_DIR = ".pw-cov"
8-
9-
beforeAll(async () => {
10-
if (!fs.existsSync(COV_DIR)) {
11-
fs.mkdirSync(COV_DIR)
12-
}
13-
})
14-
151
beforeEach(async () => {
162
await page.goto('http://localhost:3000')
173
})
184

195
afterEach(async () => {
20-
const coverage = await page.evaluate(`window.__coverage__`)
21-
if (coverage) {
22-
await fsWriteFile(path.join(COV_DIR, `${new Date().getTime()}.json`), JSON.stringify(coverage))
23-
}
6+
await jestPlaywright.saveCoverage(page)
247
})
258

269
test('use Turquoise as a default background color', async () => {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// https://github.com/playwright-community/jest-playwright/#configuration
22
module.exports = {
33
browsers: ['chromium', 'firefox', 'webkit'],
4-
server: {
4+
serverOptions: {
55
command: `npm start`,
66
port: 3000,
77
launchTimeout: 10000,
88
debug: true,
99
},
10-
launchBrowserApp: {
10+
launchOptions: {
1111
headless: true
1212
}
1313
}

0 commit comments

Comments
 (0)