<commit_before># generator-testcafe-reporter
*Scaffold out a TestCafe reporter*

[![Build Status](https://api.travis-ci.org/DevExpress/generator-testcafe-reporter.svg)](https://travis-ci.org/DevExpress/generator-testcafe-reporter)

TestCafe can build test run reports in your own format and style. What you have to do is create a custom reporter plugin.
This Yeoman generator scaffolds out such a plugin, so that you only need to write a few lines of code.

## Installation

First, install [Yeoman](http://yeoman.io) and generator-testcafe-reporter using [npm](https://www.npmjs.com/) (we assume you have pre-installed [node.js](https://nodejs.org/)).

```bash
npm install -g yo
npm install -g generator-testcafe-reporter
```

Then generate your new project:

```bash
yo generator-testcafe-reporter
```

## Author

Developer Express Inc.([http://devexpress.com](http://devexpress.com))<commit_msg>Updated Readme - Info on implementation and testing added<commit_after># generator-testcafe-reporter
*Scaffold out a TestCafe reporter*

[![Build Status](https://api.travis-ci.org/DevExpress/generator-testcafe-reporter.svg)](https://travis-ci.org/DevExpress/generator-testcafe-reporter)

TestCafe can build test run reports in your own format and style. What you have to do is create a custom reporter plugin.
This Yeoman generator scaffolds out such a plugin, so that you only need to write a few lines of code.

## Installation

First, install [Yeoman](http://yeoman.io) and generator-testcafe-reporter using [npm](https://www.npmjs.com/) (we assume you have pre-installed [node.js](https://nodejs.org/)).

```bash
npm install -g yo
npm install -g generator-testcafe-reporter
```

Then generate your new project:

```bash
yo generator-testcafe-reporter
```

##Implementing the Reporter

Now that the reporter has been scaffolded, look at the `src/index.js` file.

You have to implement four methods:

```js
reportTaskStart (/* startTime, userAgents, testCount */) {
	throw new Error('Not implemented');
},

reportFixtureStart (/* name, path */) {
	throw new Error('Not implemented');
},

reportTestDone (/* name, errs, durationMs, unstable, screenshotPath */) {
	throw new Error('Not implemented');
},

reportTaskDone (/* endTime, passed */) {
	throw new Error('Not implemented');
}
```

They should output the desired information at certain moments during test run.

* `reportTaskStart` - fires when a test task is started (i.e., at the beginning of testing);
* `reportFixtureStart` - fires each time a fixture is started;
* `reportTestDone` - fires each time a test is finished;
* `reportTaskDone` - fires when the entire task is finished (i.e., at the end of testing).

All the required data is provided to these methods through their parameters.

To output information, use helper methods and libraries exposed by the `ReporterPluginHost` object (**[TODO - documentation]**). The object you are currently editing will be mixed in with `ReporterPluginHost`, so you can refer to its methods by using `this`.

**Example**

```js
reportTaskStart (startTime, userAgents, testCount) {
	var uaList = userAgents
		.map(ua => this.chalk.blue(ua))
		.join(', ');

	this.startTime = startTime;
	this.testCount = testCount;

	this.setIndent(0)
		.useWordWrap(true)
		.write(this.chalk.bold(`Running tests in: ${uaList}`))
		.newline()
		.newline();
},
```
 
##Testing the Reporter

In addition to production parts of the reporter, this generator scaffolds a convenient testing infrastructure.

To get it to work, you need to provide baseline reports in your format.

First, you need to know what data to use in these reports. There are two ways to find this:

* Refer to the test data at `/generators/app/templates/test/data/test-calls.js`, study this JSON file and figure out the meaning of the values in there.
* An easier way is to use an existing reporter - say, the *list* reporter at https://github.com/DevExpress/testcafe-reporter-list. You can either run the `preview` Gulp task to view the report in your terminal, or find the etalon report at `/test/data/report-without-colors`.

Then, compose two baseline reports by presenting the data you discovered in the desired format.

* A regular report. Put it to `/test/data/` and name it `report-without-colors`.
* A colored report, which is a JSON file that consists of a single string - the report text with additional color information specified using [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code). Put this JSON file to `/test/data/` and name it `report-with-colors.json`.

You can now use the `test` Gulp task to test that your reporter works well.

##Preview the Report

You can preview a report built by your reporter using the `preview` Gulp task that is automatically generated for you.

##Publish the Reporter

To publish the reporter at npm, use the `publish` Gulp task.

## Author

Developer Express Inc.([http://devexpress.com](http://devexpress.com))
{'fraction_non_alphanumeric': 0.10644768856447688, 'fraction_numerical': 0.00020275750202757503, 'mean_word_length': 4.487208008898777, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5148633', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1416, 'n_words': 586}