-
Notifications
You must be signed in to change notification settings - Fork 2
/
reportConfig.ts
75 lines (66 loc) · 1.86 KB
/
reportConfig.ts
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
64
65
66
67
68
69
70
71
72
73
74
75
import {
Reporter,
FullConfig,
Suite,
TestCase,
TestError,
TestResult,
TestStep,
} from '@playwright/test/reporter';
import { createLogger, format, transports } from 'winston';
import { existsSync, mkdirSync } from 'fs';
const logDir = 'logs';
if (!existsSync(logDir)) {
mkdirSync(logDir);
}
const logger = createLogger({
level: 'info',
format: format.json(),
transports: [
new transports.Console(),
new transports.File({ filename: 'logs/info.log' }),
],
});
export default class MyReporter implements Reporter {
/**
* Logs the number of tests in the suite at the beginning of the test run.
* @param config - The full configuration object.
* @param suite - The test suite.
*/
onBegin(config: FullConfig, suite: Suite): void {
logger.info(`Starting the run with ${suite.allTests().length} tests`);
}
/**
* Logs the start of each test case.
* @param test - The test case.
*/
onTestBegin(test: TestCase): void {
logger.info(`Test Case Started: ${test.title}`);
}
/**
* Logs the completion of each test case and its status.
* @param test - The test case.
* @param result - The test result.
*/
onTestEnd(test: TestCase, result: TestResult): void {
logger.info(`Test Case Completed: ${test.title} Status: ${result.status}`);
}
/**
* Logs the execution of each test step if it belongs to the "test.step" category.
* @param test - The test case.
* @param result - The test result.
* @param step - The test step.
*/
onStepBegin(test: TestCase, result: TestResult, step: TestStep): void {
if (step.category === 'test.step') {
logger.info(`Executing Step: ${step.title}`);
}
}
/**
* Logs the error message when an error occurs during the test execution.
* @param error - The test error.
*/
onError(error: TestError): void {
logger.error(error.message);
}
}