Skip to content

Commit 8467e76

Browse files
authored
feat: Include test tags and annotations in test report (#58)
* Add test annotations and tags to test report * Add integration test for annotations/tags support
1 parent 9c1fe09 commit 8467e76

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

src/reporter.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,16 @@ export default class SauceReporter implements Reporter {
433433

434434
const lines = getLines(testCase);
435435

436+
const metadata: Record<string, unknown> = {};
437+
if (testCase.id) {
438+
metadata.id = testCase.id;
439+
}
440+
if (testCase.tags.length > 0) {
441+
metadata.tags = testCase.tags;
442+
}
443+
if (testCase.annotations.length > 0) {
444+
metadata.annotations = testCase.annotations;
445+
}
436446
const isSkipped = testCase.outcome() === 'skipped';
437447
const test = suite.withTest(testCase.title, {
438448
status: isSkipped
@@ -446,12 +456,8 @@ export default class SauceReporter implements Reporter {
446456
: undefined,
447457
startTime: lastResult.startTime,
448458
code: new TestCode(lines),
459+
metadata,
449460
});
450-
if (testCase.id) {
451-
test.metadata = {
452-
id: testCase.id,
453-
};
454-
}
455461

456462
for (const attachment of lastResult.attachments) {
457463
if (!attachment.path && !attachment.body) {

tests/integration/playwright.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ const config: PlaywrightTestConfig = {
3434
name: 'Failing Suites',
3535
testMatch: 'tests/failing.test.js',
3636
},
37+
{
38+
name: 'Annotation tests',
39+
testMatch: 'tests/annotation.test.ts',
40+
},
3741
],
3842
};
3943

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('@implicit tag in title', async ({ page }) => {
4+
await page.goto('https://www.saucedemo.com/');
5+
6+
expect(await page.title()).toBe('Swag Labs');
7+
});
8+
9+
test('explicit tag argument', { tag: '@explicit' }, async ({ page }) => {
10+
await page.goto('https://www.saucedemo.com/');
11+
12+
expect(await page.title()).toBe('Swag Labs');
13+
});
14+
15+
test('built in annotation', async ({ page }) => {
16+
test.slow();
17+
18+
await page.goto('https://www.saucedemo.com/');
19+
20+
expect(await page.title()).toBe('Swag Labs');
21+
});
22+
23+
test(
24+
'annotations',
25+
{ annotation: { type: 'static annotation' } },
26+
async ({ page }) => {
27+
test.info().annotations.push({
28+
type: 'runtime annotation',
29+
description: 'annotation added during test execution',
30+
});
31+
await page.goto('https://www.saucedemo.com/');
32+
33+
expect(await page.title()).toBe('Swag Labs');
34+
},
35+
);

0 commit comments

Comments
 (0)