mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-21 07:00:37 +03:00
improve playwright coverage
This commit is contained in:
@@ -1,22 +1,15 @@
|
||||
const fs = require('fs');
|
||||
const { basename, dirname, join } = require('path');
|
||||
const v8toIstanbul = require('v8-to-istanbul');
|
||||
const { tmpCoverageDirectory } = require('@~local/config/playwright.coverage');
|
||||
|
||||
module.exports = async (coverageOutputDir, sourceDir, coverage, testfile) => {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const entry of coverage) {
|
||||
process.chdir(sourceDir);
|
||||
const converter = v8toIstanbul('', 0, { source: entry.source });
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await converter.load();
|
||||
converter.applyCoverage(entry.functions);
|
||||
|
||||
module.exports = async (coverageOutputDir, coverage, testfile) => {
|
||||
if (coverage) {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
const coveragePath = join(
|
||||
coverageOutputDir,
|
||||
`${tmpCoverageDirectory}/${basename(dirname(testfile))}_${Date.now()}.json`
|
||||
);
|
||||
fs.mkdirSync(dirname(coveragePath), { recursive: true });
|
||||
fs.writeFileSync(coveragePath, JSON.stringify(converter.toIstanbul()));
|
||||
fs.writeFileSync(coveragePath, coverage);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -54,10 +54,8 @@ const createRollupBundle = async (testDir, useEsbuild, dev) => {
|
||||
};
|
||||
|
||||
module.exports = (useEsbuild = true) => {
|
||||
const originalCwd = process.cwd();
|
||||
let url;
|
||||
let close;
|
||||
let output;
|
||||
|
||||
const isDev = (config, timeout) =>
|
||||
config.globalTimeout === 0 && timeout === 0 && config.workers === 1;
|
||||
@@ -68,25 +66,20 @@ module.exports = (useEsbuild = true) => {
|
||||
test.setTimeout(0);
|
||||
}
|
||||
|
||||
({ close, url, output } = await createRollupBundle(
|
||||
dirname(file),
|
||||
useEsbuild,
|
||||
isDev(config, timeout)
|
||||
));
|
||||
({ close, url } = await createRollupBundle(dirname(file), useEsbuild, isDev(config, timeout)));
|
||||
});
|
||||
|
||||
test.beforeEach(async ({ page, browserName }, { config, timeout }) => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto(url, { waitUntil: 'domcontentloaded' });
|
||||
await page.waitForTimeout(500);
|
||||
if (browserName === 'chromium' && !isDev(config, timeout)) {
|
||||
await page.coverage.startJSCoverage();
|
||||
}
|
||||
});
|
||||
|
||||
test.afterEach(async ({ page, browserName }, { file, config, timeout }) => {
|
||||
if (browserName === 'chromium' && !isDev(config, timeout)) {
|
||||
const coverage = await page.coverage.stopJSCoverage();
|
||||
await collectCoverage(originalCwd, dirname(output), coverage, file);
|
||||
const coverageJSON = await page
|
||||
.evaluate(() => JSON.stringify(window.__coverage__))
|
||||
.catch(() => null);
|
||||
await collectCoverage(process.cwd(), coverageJSON, file);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user