-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathindex.ts
More file actions
63 lines (53 loc) · 2.11 KB
/
Copy pathindex.ts
File metadata and controls
63 lines (53 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import type { ZephyrOptions, ZephyrStatus, ZephyrTestResult } from '../types/zephyr.types';
import type { Reporter, TestCase, TestResult, TestStatus } from '@playwright/test/reporter';
import { ZephyrService } from './zephyr.service';
function convertPwStatusToZephyr(status: TestStatus): ZephyrStatus {
if (status === 'passed') return 'Pass';
if (status === 'failed') return 'Fail';
if (status === 'skipped') return 'Not Executed';
if (status === 'timedOut') return 'Blocked';
return 'Not Executed';
}
class ZephyrReporter implements Reporter {
private zephyrService!: ZephyrService;
private testResults: ZephyrTestResult[] = [];
private projectKey!: string;
private testCaseKeyPattern = /\[(.*?)\]/;
private options: ZephyrOptions;
private readonly ignoreFailedRetries: boolean;
environment: string | undefined;
constructor(options: ZephyrOptions) {
this.options = options;
this.ignoreFailedRetries = options.ignoreFailedRetries || false;
}
async onBegin() {
this.projectKey = this.options.projectKey;
this.environment = this.options.environment;
this.zephyrService = new ZephyrService(this.options);
}
onTestEnd(test: TestCase, result: TestResult) {
if (this.ignoreFailedRetries && test.retries !== result.retry && result.status !== 'passed') {
return;
}
if (test.title.match(this.testCaseKeyPattern) && test.title.match(this.testCaseKeyPattern)!.length > 1) {
const [, projectName] = test.titlePath();
const [, testCaseId] = test.title.match(this.testCaseKeyPattern)!;
const testCaseKey = `${this.projectKey}-${testCaseId}`;
const status = convertPwStatusToZephyr(result.status);
this.testResults.push({
testCaseKey,
status,
environment: this.environment ?? projectName ?? 'Playwright',
executionDate: new Date().toISOString(),
});
}
}
async onEnd() {
if (this.testResults.length > 0) {
await this.zephyrService.createRun(this.testResults);
} else {
console.log(`There are no tests with such ${this.testCaseKeyPattern} key pattern`);
}
}
}
export default ZephyrReporter;