-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[frontend] pass to v8 e2e test & coverage
- Loading branch information
1 parent
f09ede7
commit 8f0e498
Showing
8 changed files
with
809 additions
and
1,057 deletions.
There are no files selected for viewing
614 changes: 307 additions & 307 deletions
614
openbas-front/.yarn/releases/yarn-4.5.1.cjs → openbas-front/.yarn/releases/yarn-4.5.3.cjs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
defaultSemverRangePrefix: "" | ||
|
||
nodeLinker: node-modules | ||
yarnPath: .yarn/releases/yarn-4.5.1.cjs | ||
defaultSemverRangePrefix: "" | ||
|
||
yarnPath: .yarn/releases/yarn-4.5.3.cjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,7 @@ | |
"@types/react-syntax-highlighter": "15", | ||
"@types/seamless-immutable": "7.1.19", | ||
"@types/uuid": "10.0.0", | ||
"@typescript-eslint/parser": "8.15.0", | ||
"@typescript-eslint/parser": "8.16.0", | ||
"@vitejs/plugin-react": "4.3.0", | ||
"chokidar": "4.0.1", | ||
"cross-env": "7.0.3", | ||
|
@@ -115,12 +115,12 @@ | |
"fs-extra": "11.2.0", | ||
"globals": "15.12.0", | ||
"jsdom": "25.0.1", | ||
"nyc": "17.1.0", | ||
"monocart-coverage-reports": "2.11.3", | ||
"monocart-reporter": "2.9.11", | ||
"swagger-typescript-api": "13.0.22", | ||
"typescript": "5.7.2", | ||
"typescript-eslint": "8.15.0", | ||
"typescript-eslint": "8.16.0", | ||
"vite": "5.4.7", | ||
"vite-plugin-istanbul": "6.0.2", | ||
"vitest": "2.1.1" | ||
}, | ||
"engines": { | ||
|
@@ -136,10 +136,11 @@ | |
"check-ts": "tsc --noEmit", | ||
"i18n-checker": "node i18n-checker.js", | ||
"generate-types-from-api": "swagger-typescript-api --no-client -p http://localhost:8080/api-docs -o src/utils -n api-types.d.ts --sort-types", | ||
"test:e2e": "yarn playwright test", | ||
"test:e2e:ui": "yarn playwright test --ui", | ||
"generate-test-e2e": "npx playwright codegen http://localhost:3001/", | ||
"test:e2e:coverage": "npx nyc report --reporter=html && start \"\" coverage/index.html" | ||
"test:e2e": "yarn playwright test --workers=1 --retries=2", | ||
"test:e2e:ui": "yarn playwright test --ui --workers=1", | ||
"generate-test-e2e": "yarn playwright codegen http://localhost:3000/", | ||
"show-report-e2e": "start \"\" test-results/report.html && start \"\" test-results/coverage/index.html", | ||
"test:e2e:coverage": "E2E_COVERAGE=true yarn playwright test && yarn show-report-e2e" | ||
}, | ||
"resolutions": { | ||
"mini-css-extract-plugin": "2.9.1", | ||
|
@@ -149,5 +150,5 @@ | |
"workspaces": [ | ||
"packages/*" | ||
], | ||
"packageManager": "[email protected].1" | ||
"packageManager": "[email protected].3" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { CoverageReportOptions } from 'monocart-coverage-reports'; | ||
|
||
// https://github.com/cenfun/monocart-coverage-reports | ||
const coverageOptions: CoverageReportOptions = { | ||
|
||
name: 'OpenBAS Playwright Coverage Report', | ||
|
||
reports: [ | ||
'console-details', | ||
'v8', | ||
'lcovonly', | ||
], | ||
|
||
entryFilter: { | ||
'**/node_modules/**': false, | ||
'**/**': true, | ||
}, | ||
|
||
sourceFilter: { | ||
'**/node_modules/**': false, | ||
'**/**': true, | ||
}, | ||
|
||
outputDir: './test-results/coverage', | ||
}; | ||
|
||
export default coverageOptions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,52 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any, no-underscore-dangle */ | ||
import { test as baseTest } from '@playwright/test'; | ||
import * as crypto from 'crypto'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { Page, test as testBase } from '@playwright/test'; | ||
import MCR from 'monocart-coverage-reports'; | ||
|
||
const istanbulCLIOutput = path.join(process.cwd(), '.nyc_output'); | ||
import coverageOptions from '../conf/mcr.config'; | ||
|
||
export function generateUUID(): string { | ||
return crypto.randomBytes(16).toString('hex'); | ||
} | ||
// fixtures | ||
const test = testBase.extend<{ | ||
autoTestFixture: string; | ||
}>({ | ||
autoTestFixture: [async ({ context }, use) => { | ||
const activateCoverage = process.env.E2E_COVERAGE; | ||
const isChromium = test.info().project.name === 'chromium'; | ||
|
||
export const test = baseTest.extend({ | ||
context: async ({ context }, use) => { | ||
await context.addInitScript(() => window.addEventListener('beforeunload', () => (window as any).collectIstanbulCoverage(JSON.stringify((window as any).__coverage__)))); | ||
await fs.promises.mkdir(istanbulCLIOutput, { recursive: true }); | ||
await context.exposeFunction('collectIstanbulCoverage', (coverageJSON: string) => { | ||
if (coverageJSON) fs.writeFileSync(path.join(istanbulCLIOutput, `playwright_coverage_${generateUUID()}.json`), coverageJSON); | ||
}); | ||
await use(context); | ||
for (const page of context.pages()) { | ||
// eslint-disable-next-line no-await-in-loop | ||
await page.evaluate(() => (window as any).collectIstanbulCoverage(JSON.stringify((window as any).__coverage__))); | ||
const handlePageEvent = async (page: Page) => { | ||
await Promise.all([ | ||
page.coverage.startJSCoverage({ | ||
resetOnNavigation: false, | ||
}), | ||
page.coverage.startCSSCoverage({ | ||
resetOnNavigation: false, | ||
}), | ||
]); | ||
}; | ||
|
||
// console.log('autoTestFixture setup...'); | ||
// coverage API is chromium only | ||
if (activateCoverage && isChromium) { | ||
context.on('page', handlePageEvent); | ||
} | ||
|
||
await use('autoTestFixture'); | ||
|
||
// console.log('autoTestFixture teardown...'); | ||
if (activateCoverage && isChromium) { | ||
context.off('page', handlePageEvent); | ||
const coverageList = await Promise.all(context.pages().map(async (page) => { | ||
const jsCoverage = await page.coverage.stopJSCoverage(); | ||
const cssCoverage = await page.coverage.stopCSSCoverage(); | ||
return [...jsCoverage, ...cssCoverage]; | ||
})); | ||
// console.log(coverageList.map((item) => item.url)); | ||
const mcr = MCR(coverageOptions); | ||
await mcr.add(coverageList.flat()); | ||
} | ||
}, | ||
}, { | ||
scope: 'test', | ||
auto: true, | ||
}], | ||
}); | ||
|
||
export const { expect } = test; | ||
// eslint-disable-next-line import/prefer-default-export | ||
export { test }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.