mirror of
https://github.com/openobserve/openobserve.git
synced 2026-11-04 16:09:05 +00:00
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Added support for code coverage reporting with the integration of `vite-plugin-istanbul`. - Introduced a new configuration file for code coverage settings. - **Improvements** - Updated project to use ECMAScript modules for better compatibility. - Enhanced UI test coverage with additional test cases and improved error handling. - Refactored test suites to utilize a custom module for better organization and maintainability. - Improved the login process and dashboard loading in test cases for better reliability. - **Bug Fixes** - Resolved issues related to import statements affecting test execution. - **Documentation** - Updated `.gitignore` to exclude coverage directories from version control. These updates enhance the functionality, maintainability, and reliability of the application and its testing framework. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
44 lines
1.5 KiB
JavaScript
44 lines
1.5 KiB
JavaScript
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
import * as crypto from 'crypto';
|
|
import { test as baseTest } from '@playwright/test';
|
|
|
|
const istanbulCLIOutput = path.join(process.cwd(), '.nyc_output');
|
|
|
|
export function generateUUID() {
|
|
return crypto.randomBytes(16).toString('hex');
|
|
}
|
|
|
|
export const test = baseTest.extend({
|
|
context: async ({ context }, use) => {
|
|
await context.addInitScript(() =>
|
|
window.addEventListener('beforeunload', () => {
|
|
try {
|
|
(window).collectIstanbulCoverage(JSON.stringify((window).__coverage__))
|
|
} catch (error) {
|
|
console.error('Failed to collect coverage on page unload:', error);
|
|
}
|
|
}),
|
|
);
|
|
await fs.promises.mkdir(istanbulCLIOutput, { recursive: true });
|
|
await context.exposeFunction('collectIstanbulCoverage', async (coverageJSON) => {
|
|
if (!coverageJSON) return;
|
|
const filename = path.join(istanbulCLIOutput, `playwright_coverage_${generateUUID()}.json`);
|
|
try {
|
|
await fs.promises.writeFile(filename, coverageJSON);
|
|
} catch (error) {
|
|
console.error('Failed to write coverage data:', error);
|
|
}
|
|
});
|
|
await use(context);
|
|
await Promise.all(context.pages().map(async (page) => {
|
|
try {
|
|
await page.evaluate(() => (window).collectIstanbulCoverage(JSON.stringify((window).__coverage__)))
|
|
} catch (error) {
|
|
console.error('Failed to collect final coverage for page:', error);
|
|
}
|
|
}));
|
|
}
|
|
});
|
|
|
|
export const expect = test.expect; |