mirror of
https://github.com/openobserve/openobserve.git
synced 2026-11-04 16:09:05 +00:00
### **PR Type**
Tests, Enhancement
___
### **Description**
- Add conditional artifact upload guards
- Make report artifact names matrix-aware
- Preserve stream name test comment clarity
___
### Diagram Walkthrough
```mermaid
flowchart LR
tests["Playwright tests"] -- "produce reports/coverage" --> outputs["Reports & Coverage"]
outputs -- "conditional check" --> uploadPR["Upload Playwright Report"]
outputs -- "conditional check" --> uploadCov["Upload Coverage Report"]
matrix["Matrix folder name"] -- "used in name" --> uploadPR
```
<details> <summary><h3> File Walkthrough</h3></summary>
<table><thead><tr><th></th><th align="left">Relevant
files</th></tr></thead><tbody><tr><td><strong>Documentation</strong></td><td><table>
<tr>
<td>
<details>
<summary><strong>streamname.spec.js</strong><dd><code>Comment clarity
for ingestion loop</code>
</dd></summary>
<hr>
tests/ui-testing/playwright-tests/Streams/streamname.spec.js
- Fix comment wording to singular
- No functional code changes
</details>
</td>
<td><a
href="https://github.com/openobserve/openobserve/pull/8190/files#diff-49828efdc034005c097422deadc8b892bb1e54942d024e40d640fd10c5aa2793">+1/-1</a>
</td>
</tr>
</table></td></tr><tr><td><strong>Enhancement</strong></td><td><table>
<tr>
<td>
<details>
<summary><strong>playwright.yml</strong><dd><code>Conditional artifact
uploads and better naming</code>
</dd></summary>
<hr>
.github/workflows/playwright.yml
<ul><li>Add hashFiles guard for report upload<br> <li> Rename report
artifact to include matrix folder<br> <li> Add guard for coverage report
upload<br> <li> Add explicit step name for report upload</ul>
</details>
</td>
<td><a
href="https://github.com/openobserve/openobserve/pull/8190/files#diff-7afcd2d8f7b49bda74843f209eefb7b2da45f7e7803bf2e4bd636699b76aa2d3">+5/-3</a>
</td>
</tr>
</table></td></tr></tr></tbody></table>
</details>
___
45 lines
1.6 KiB
JavaScript
45 lines
1.6 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 testLogger = require('./utils/test-logger.js');
|
|
|
|
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) {
|
|
testLogger.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) {
|
|
testLogger.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) {
|
|
testLogger.error('Failed to collect final coverage for page', { error });
|
|
}
|
|
}));
|
|
}
|
|
});
|
|
|
|
export const expect = test.expect; |