Skip to content

Commit 4ebc0c9

Browse files
committed
Reporter + weights
1 parent 5108eca commit 4ebc0c9

File tree

5 files changed

+64
-7
lines changed

5 files changed

+64
-7
lines changed

libraries/__shared__/tests/advanced-tests.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
*/
1717

1818
import {expect, test} from '@playwright/test';
19-
import {getProp, each} from "./util";
19+
import {getProp, each, weight} from "./util";
20+
2021

2122
each(() => {
22-
test.describe('advanced support', () => {
23+
test.describe('advanced support', weight(2), () => {
2324
test.describe('attributes and properties', () => {
2425
test('will pass array data as a property', async ({page}) => {
2526
const ce = page.locator('#ce-with-properties');
@@ -37,9 +38,9 @@ each(() => {
3738
})
3839
});
3940

40-
test.describe('events', () => {
41+
test.describe('events', weight(1), () => {
4142

42-
test("can declaratively listen to a lowercase DOM event dispatched by a Custom Element", async ({page}) => {
43+
test("can declaratively listen to a lowercase DOM event dispatched by a Custom Element", weight(2), async ({page}) => {
4344
const ce = page.locator('#ce-with-declarative-event');
4445
await expect(page.getByText(/lowercase:/)).toHaveText(/false/);
4546
await ce.click();

libraries/__shared__/tests/basic-tests.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
*/
1717

1818
import {expect, test} from '@playwright/test';
19-
import {each, getPropOrAttr} from './util';
19+
import {each, getPropOrAttr, weight} from './util';
2020

2121

2222
each(() => {
23-
test.describe("basic support", () => {
23+
test.describe("basic support", weight(3), () => {
2424
test.describe("no children", () => {
2525
test("can display a Custom Element with no children", async ({page}) => {
2626
await expect(page.locator('#ce-without-children')).toBeAttached();

libraries/__shared__/tests/playwright.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ export default defineConfig({
99
name: 'chromium',
1010
use: { ...devices['Desktop Chrome'] },
1111
},
12+
{
13+
name: 'firefox',
14+
use: { ...devices['Desktop Firefox'] },
15+
},
1216
],
1317
webServer: {
1418
command: 'npm run serve',
1519
url: 'http://localhost:8080',
1620
reuseExistingServer: !process.env.CI,
1721
stdout: 'ignore',
1822
stderr: 'pipe'
19-
}
23+
},
24+
reporter: './reporter.js'
2025
})
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import fs from 'node:fs';
2+
3+
4+
export default class CEEReporter {
5+
6+
results = {};
7+
8+
onTestEnd(test, result) {
9+
const [_, _browser, _file, framework, suite] = test.titlePath();
10+
((this.results[framework] ||= {})[suite] ||= {})[result.status] ||= 0
11+
this.results[framework][suite][result.status] += 1;
12+
const weight = test.annotations.filter(({type}) => type === 'weight').toReversed()[0]?.description ?? 3;
13+
(this.results[framework].weight ||= {})[result.status] ||= 0;
14+
this.results[framework].weight[result.status] += weight
15+
}
16+
17+
onEnd(result) {
18+
for (const [framework, results] of Object.entries(this.results)) {
19+
const basicPassed = results['basic support'].passed ?? 0;
20+
const basicFailed = results['basic support'].failed ?? 0;
21+
const advancedPassed = results['advanced support'].passed ?? 0;
22+
const advancedFailed = results['advanced support'].failed ?? 0;
23+
24+
const weightedPassed = results.weight.passed ?? 0;
25+
const weightedFailed = results.weight.failed ?? 0;
26+
const totalWeight = weightedPassed + weightedFailed;
27+
28+
fs.writeFileSync(`../../${framework}/results/results.json`, JSON.stringify({
29+
summary: {
30+
success: basicPassed + advancedPassed,
31+
failed: basicFailed + advancedFailed,
32+
score: totalWeight === 0 ? 0 : 100 * weightedPassed / totalWeight,
33+
basicSupport: {
34+
total: basicPassed + basicFailed,
35+
failed: basicFailed,
36+
passed: basicPassed
37+
},
38+
advancedSupport: {
39+
total: advancedPassed + advancedFailed,
40+
failed: advancedFailed,
41+
passed: advancedPassed
42+
}
43+
}
44+
}, null, 2))
45+
}
46+
}
47+
}

libraries/__shared__/tests/util.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ export const getPropOrAttr = async (ce, name) => {
99
return await getProp(ce, name) ?? ce.getAttribute(name);
1010
}
1111

12+
export const weight = (weight) => ({
13+
annotation: {type: 'weight', description: weight}
14+
})
15+
1216
export const each = (cb) => {
1317
fs.readdirSync('./harness', {withFileTypes: true}).filter(d => d.isDirectory()).forEach(({name}) => {
1418
test.describe(name, () => {

0 commit comments

Comments
 (0)