docs(reporter): added types to Reporter TypeScript example (#19917)

This commit is contained in:
Tommaso A 2023-01-06 13:39:17 +01:00 committed by GitHub
parent cd698a2258
commit 6d64edc090
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -626,25 +626,26 @@ module.exports = MyReporter;
```js tab=js-ts ```js tab=js-ts
// my-awesome-reporter.ts // my-awesome-reporter.ts
import { Reporter } from '@playwright/test/reporter'; import { FullConfig, FullResult, Reporter, Suite, TestCase, TestResult } from '@playwright/test/reporter';
class MyReporter implements Reporter { class MyReporter implements Reporter {
onBegin(config, suite) { onBegin(config: FullConfig, suite: Suite) {
console.log(`Starting the run with ${suite.allTests().length} tests`); console.log(`Starting the run with ${suite.allTests().length} tests`);
} }
onTestBegin(test) { onTestBegin(test: TestCase, result: TestResult) {
console.log(`Starting test ${test.title}`); console.log(`Starting test ${test.title}`);
} }
onTestEnd(test, result) { onTestEnd(test: TestCase, result: TestResult) {
console.log(`Finished test ${test.title}: ${result.status}`); console.log(`Finished test ${test.title}: ${result.status}`);
} }
onEnd(result) { onEnd(result: FullResult) {
console.log(`Finished the run: ${result.status}`); console.log(`Finished the run: ${result.status}`);
} }
} }
export default MyReporter; export default MyReporter;
``` ```