Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Docs Metadata #2372

Merged
merged 11 commits into from
May 11, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ checked: false
---
# Reporter Methods

To create a [reporter](README.md#implementing-the-reporter), you need to implement the following methods.
You should implement the following methods to create a [reporter](README.md#implementing-the-reporter).

> You can use [helper methods and libraries](helpers.md) within the reporter methods to output required data.
> You can use the [helper methods and libraries](helpers.md) within the reporter methods to output the required data.

## reportTaskStart

Fires when a test task starts, which happens at the beginning of testing.
Fires when a test task starts.

```text
reportTaskStart (startTime, userAgents, testCount)
Expand Down Expand Up @@ -48,53 +48,56 @@ reportTaskStart (startTime, userAgents, testCount) {
Fires each time a fixture starts.

```text
reportFixtureStart (name, path)
reportFixtureStart (name, path, meta)
```

Parameter | Type | Description
--------- | ------ | --------------------------------
`name` | String | The test fixture name.
`path` | String | The path to a test fixture file.
`meta` | Object | The fixture metadata. See [Specifying Testing Metadata](../../test-api/test-code-structure.md#specifying-testing-metadata) for more information.

**Example**

```js
reportFixtureStart (name) {
reportFixtureStart (name, path, meta) {
this.currentFixtureName = name;
this.write(`Starting fixture: ${name}`)
this.currentFixtureMeta = meta;
this.write(`Starting fixture: ${name} ${meta.fixtureID}`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.currentFixtureName = name;
this.currentFixtureMeta = meta;

this.write(`Starting fixture: ${name} ${meta.fixtureID}`)
    .newline();

But in my opinion it'd better to format in the following way (everywhere in docs):

this.currentFixtureName = name;
this.currentFixtureMeta = meta;

this
    .write(`Starting fixture: ${name} ${meta.fixtureID}`)
    .newline();

E.g.

reportTaskDone (endTime, passed) {
    const time        = this.moment(endTime).format('M/D/YYYY h:mm:ss a');
    const durationMs  = endTime - this.startTime;
    const durationStr = this.moment.duration(durationMs).format('h[h] mm[m] ss[s]');

    const result = passed === this.testCount ?
                `${this.testCount} passed` :
                `${this.testCount - passed}/${this.testCount} failed`;

    this
        .write(`Testing finished: ${time}`)
        .newline()

        .write(`Duration: ${durationStr}`)
        .newline()

        .write(result)
        .newline();
}

.newline();
}

//=> Starting fixture: First fixture
//=> Starting fixture: First fixture f-0001
```

## reportTestDone

Fires each time a test ends.

```text
reportTestDone (name, testRunInfo)
reportTestDone (name, testRunInfo, meta)
```

Parameter | Type | Description
------------- | ------ | -------------------------------------------------------------
`name` | String | The test name.
`testRunInfo` | Object | The object providing detailed information about the test run.
`meta` | Object | The test metadata. See [Specifying Testing Metadata](../../test-api/test-code-structure.md#specifying-testing-metadata) for more information.

The `testRunInfo` object has the following properties.

Property | Type | Description
---------------- | ---------------- | --------------------------------------------------------
`errs` | Array or Strings | An array of errors that occurred during a test run.
`durationMs` | Number | The time spent on test execution (in milliseconds).
`unstable` | Boolean | Specifies if the test has been marked as unstable.
`unstable` | Boolean | Specifies if the test is marked as unstable.
`screenshotPath` | String | The directory path where screenshots have been saved to.
`skipped` | Boolean | Specifies if the test was skipped.

**Example**

```js
reportTestDone (name, testRunInfo) {
reportTestDone (name, testRunInfo, meta) {
const hasErr = !!testRunInfo.errs.length;
const result = testRunInfo.skipped ? 'skipped' : hasErr ? `passed` : `failed`;

Expand All @@ -108,19 +111,22 @@ reportTestDone (name, testRunInfo) {
if (testRunInfo.screenshotPath)
title += ` (screenshots: ${testRunInfo.screenshotPath})`;

if (meta.severity)
title += ' (meta.severity)';

this.write(title)
.newline();
}

//=> failed First fixture - First test in first fixture (unstable) (screenshots: /screenshots/1445437598847)
//=> failed First fixture - First test in first fixture (unstable) (screenshots: /screenshots/1445437598847) (critical)
//=> passed First fixture - Second test in first fixture (screenshots: /screenshots/1445437598847)
//=> failed First fixture - Third test in first fixture
//=> skipped First fixture - Fourth test in first fixture
```

## reportTaskDone

Fires when the entire task ends, which happens at the end of testing.
Fires when the task ends.

```text
reportTaskDone (endTime, passed, warnings)
Expand Down Expand Up @@ -154,4 +160,4 @@ reportTaskDone (endTime, passed) {
//=> Testing finished: 8/12/2016 3:15:25 am
//=> Duration: 15m 25s
//=> 2/6 failed
```
```
Loading