Skip to content

Commit a1fe04d

Browse files
[docs] Describe passing the reporter object through the API (DevExpress#4757)
1 parent 999c351 commit a1fe04d

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ yarn.lock
1212
package-lock.json
1313
Gemfile.lock
1414
.npmrc
15+
.DS_Store

Diff for: docs/articles/documentation/extending-testcafe/reporter-plugin/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ To create a reporter plugin, go through the following steps.
2121
* [Using the Reporter Development Version](#using-the-reporter-development-version)
2222
* [Publishing the Reporter to npm](#publishing-the-reporter-to-npm)
2323

24+
> You can also specify a reporter object in the [TestCafe programming interface](../../using-testcafe/programming-interface/runner.md#specifying-a-custom-reporter). However, a reporter plugin is easier to reuse and maintain.
25+
2426
## Generating a Reporter Project
2527

2628
First, install [Yeoman](http://yeoman.io) and `generator-testcafe-reporter` using [npm](https://www.npmjs.com/).

Diff for: docs/articles/documentation/using-testcafe/programming-interface/runner.md

+28-2
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,15 @@ Configures TestCafe's reporting feature.
314314

315315
```text
316316
reporter(name, output) → this
317-
reporter([ name | { name, output }]) → this
317+
reporter(fn) → this
318+
reporter([ name | { name, output } | fn ]) → this
318319
```
319320

320321
Parameter | Type | Description | Default
321322
------------------------ | --------------------------- | ----------------------------------------------- | --------
322-
`name` | String | The name of the [reporter](../common-concepts/reporters.md) to use.
323+
`name` | String | The name of the [reporter](../common-concepts/reporters.md).
323324
`output` *(optional)* | String | Writable Stream implementer | The file path where the report is written or the output stream. | `stdout`
325+
`fn` | A function that [returns a custom reporter object](#specifying-a-custom-reporter).
324326

325327
To use a single reporter, specify a reporter name and, optionally, an output target as the second parameter.
326328

@@ -351,6 +353,30 @@ runner.reporter(['spec', {
351353
}]);
352354
```
353355

356+
#### Specifying a Custom Reporter
357+
358+
You can implement a [custom reporter](../../extending-testcafe/reporter-plugin/README.md) in the code that launches tests. This approach allows you to implement your reporter faster if you need it for a single project or do not want to publish a reporter plugin.
359+
360+
Pass a *function* that returns the custom reporter object to the `runner.reporter` method.
361+
362+
```js
363+
import { createTestCafe } from 'testcafe';
364+
365+
const customReporter = () => {
366+
return {
367+
async reportTaskStart (startTime, userAgents, testCount) { /* ... */ },
368+
async reportFixtureStart (name, path, meta) { /* ... */ },
369+
async reportTestDone (name, testRunInfo, meta) { /* ... */ },
370+
async reportTaskDone (endTime, passed, warnings, result) { /* ... */ }
371+
};
372+
};
373+
374+
const testcafe = await createTestCafe(/* [...] */);
375+
const runner = testcafe.createRunner();
376+
377+
await runner.reporter(customReporter);
378+
```
379+
354380
#### Implementing a Custom Stream
355381

356382
```js

0 commit comments

Comments
 (0)