docs: Added types to custom reporter typescript example (#20191)

This commit is contained in:
Adi 2023-01-28 19:38:42 +02:00 committed by GitHub
parent 2b499bd5d6
commit 32724cd5ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 10 deletions

View file

@ -34,22 +34,22 @@ 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 { Reporter, FullConfig, Suite, TestCase, TestResult, FullResult } 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) {
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}`);
} }
} }

View file

@ -313,22 +313,22 @@ export interface FullResult {
* *
* ```js * ```js
* // my-awesome-reporter.ts * // my-awesome-reporter.ts
* import { Reporter } from '@playwright/test/reporter'; * import { Reporter, FullConfig, Suite, TestCase, TestResult, FullResult } 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) {
* 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}`);
* } * }
* } * }