Skip to content

Commit 8c0785e

Browse files
committed
chore: integrate Monocart coverage reports, update configs, and cleanup dependencies
1 parent 64ca89f commit 8c0785e

File tree

10 files changed

+218
-110
lines changed

10 files changed

+218
-110
lines changed

.github/workflows/test.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ jobs:
6363
uses: codecov/codecov-action@v5
6464
with:
6565
token: ${{ secrets.CODECOV_TOKEN }}
66+
files: ./coverage/unit/lcov.info
67+
68+
- uses: actions/upload-artifact@v4
69+
if: ${{ !cancelled() }}
70+
with:
71+
name: unit-test-report
72+
path: |
73+
coverage/
74+
retention-days: 30
6675

6776
e2e_tests:
6877
name: Playwright E2E test
@@ -102,9 +111,17 @@ jobs:
102111
- name: E2E test
103112
run: pnpm test:e2e
104113

114+
- name: Update coverage report
115+
uses: codecov/codecov-action@v5
116+
with:
117+
token: ${{ secrets.CODECOV_TOKEN }}
118+
files: ./coverage/e2e/lcov.info
119+
105120
- uses: actions/upload-artifact@v4
106121
if: ${{ !cancelled() }}
107122
with:
108-
name: playwright-report
109-
path: playwright-report/
123+
name: e2e-test-report
124+
path: |
125+
playwright-report/
126+
coverage/
110127
retention-days: 30

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,15 @@
3535
"@playwright/test": "1.55.1",
3636
"@testing-library/user-event": "^14.6.1",
3737
"@testing-library/vue": "^8.1.0",
38-
"@types/html": "^1.0.4",
3938
"@types/node": "^24.5.2",
4039
"@vitejs/plugin-vue": "^6.0.1",
4140
"@vitest/coverage-v8": "^3.2.4",
4241
"cross-env": "^7.0.3",
4342
"eslint": "^9.36.0",
4443
"eslint-plugin-vuejs-accessibility": "^2.4.1",
4544
"happy-dom": "^18.0.1",
46-
"html": "^1.0.0",
4745
"lint-staged": "^16.2.0",
46+
"monocart-coverage-reports": "^2.12.9",
4847
"msw": "^2.11.3",
4948
"rollup-plugin-analyzer": "^4.0.0",
5049
"simple-git-hooks": "^2.13.1",

playwright.config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ export default defineConfig({
2828
['html', { open: 'never' }],
2929
isCI ? ['github'] : ['list'],
3030
],
31+
32+
globalSetup: './playwright/global.setup.ts',
33+
globalTeardown: './playwright/global.teardown.ts',
34+
3135
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
3236
use: {
3337
/* Base URL to use in actions like `await page.goto('/')`. */
3438
baseURL,
3539

36-
navigationTimeout: isCI ? 10_000 : 10_000,
37-
actionTimeout: isCI ? 10_000 : 10_000,
40+
navigationTimeout: isCI ? 10_000 : 20_000,
41+
actionTimeout: isCI ? 10_000 : 20_000,
3842

3943
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
4044
screenshot: 'only-on-failure',

playwright/extends.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,56 @@
1+
import type { Page } from '@playwright/test'
12
import { test as base } from '@playwright/test'
3+
import MCR from 'monocart-coverage-reports'
24
import { ConduitPageObject } from 'page-objects/conduit.page-object'
5+
import coverageOptions from './mcr.config'
36

47
export const test = base.extend<{
58
conduit: ConduitPageObject
9+
autoTestFixture: string
610
}>({
711
conduit: async ({ page }, use) => {
812
const buyscoutPageObject = new ConduitPageObject(page)
913
await use(buyscoutPageObject)
1014
},
15+
16+
autoTestFixture: [async ({ context }, use) => {
17+
const isChromium = test.info().project.name === 'chromium'
18+
19+
// eslint-disable-next-line unicorn/consistent-function-scoping
20+
const handlePageEvent = async (page: Page) => {
21+
await Promise.all([
22+
page.coverage.startJSCoverage({
23+
resetOnNavigation: false,
24+
}),
25+
page.coverage.startCSSCoverage({
26+
resetOnNavigation: false,
27+
}),
28+
])
29+
}
30+
31+
// coverage API is chromium only
32+
if (isChromium) {
33+
context.on('page', handlePageEvent)
34+
}
35+
36+
await use('autoTestFixture')
37+
38+
if (isChromium) {
39+
context.off('page', handlePageEvent)
40+
const coverageList = await Promise.all(context.pages().map(async page => {
41+
const jsCoverage = await page.coverage.stopJSCoverage()
42+
const cssCoverage = await page.coverage.stopCSSCoverage()
43+
return [...jsCoverage, ...cssCoverage]
44+
}))
45+
// console.log(coverageList.map((item) => item.url));
46+
47+
const mcr = MCR(coverageOptions)
48+
await mcr.add(coverageList.flat())
49+
}
50+
}, {
51+
scope: 'test',
52+
auto: true,
53+
}],
1154
})
1255

1356
test.afterEach(async ({ page }, testInfo) => {

playwright/global.setup.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { FullConfig } from '@playwright/test'
2+
import MCR from 'monocart-coverage-reports'
3+
import coverageOptions from './mcr.config'
4+
5+
async function globalSetup(_config: FullConfig) {
6+
const mcr = MCR(coverageOptions)
7+
mcr.cleanCache()
8+
}
9+
10+
export default globalSetup

playwright/global.teardown.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { FullConfig } from '@playwright/test'
2+
import MCR from 'monocart-coverage-reports'
3+
import coverageOptions from './mcr.config'
4+
5+
async function globalTeardown(_config: FullConfig) {
6+
const mcr = MCR(coverageOptions)
7+
await mcr.generate()
8+
}
9+
10+
export default globalTeardown

playwright/mcr.config.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import type { CoverageReportOptions } from 'monocart-coverage-reports'
2+
3+
// https://github.com/cenfun/monocart-coverage-reports
4+
const coverageOptions: CoverageReportOptions = {
5+
6+
name: 'Playwright Coverage Report',
7+
8+
reports: [
9+
'text',
10+
'v8',
11+
'v8-json',
12+
'lcovonly',
13+
],
14+
15+
/**
16+
* V8 entity filter. The entry.url is the URL of the entity.
17+
* @example http://localhost:4173/assets/index-Bn6Ml0wL.js
18+
* @example https://fonts.googleapis.com/css?family=Titillium+Web:700
19+
* @example https://demo.realworld.io/main.css
20+
* @example https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css
21+
*/
22+
entryFilter: entry => {
23+
const excludeList = [
24+
'googleapis.com',
25+
'realworld.(io|show)/main.css',
26+
'ionicons.min.css',
27+
]
28+
for (const regexp of excludeList) {
29+
if (new RegExp(regexp).test(entry.url)) return false
30+
}
31+
return true
32+
},
33+
34+
/**
35+
* Source filter. The sourcePath is the path of the source file.
36+
* @example src/components/HelloWorld.vue
37+
* @example src/config.ts
38+
* @example node_modules/.pnpm/@[email protected]/node_modules/@vue/devtools-kit/dist/index.js
39+
*/
40+
sourceFilter: sourcePath => {
41+
if (sourcePath.includes('node_modules/')) return false
42+
return true
43+
},
44+
45+
outputDir: './coverage/e2e',
46+
}
47+
48+
export default coverageOptions

playwright/utils/prettify.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)