An open API service indexing awesome lists of open source software.

https://github.com/peerigon/xunit-file

Basically the same reporter as mocha's xunit reporter, but writes the output in a file.
https://github.com/peerigon/xunit-file

Last synced: 12 months ago
JSON representation

Basically the same reporter as mocha's xunit reporter, but writes the output in a file.

Awesome Lists containing this project

README

          

xunit-file
==========

Basically the same reporter as mocha's xunit reporter, but writes the output to a file.

[![](https://img.shields.io/npm/v/xunit-file.svg)](https://www.npmjs.com/package/xunit-file)
[![](https://img.shields.io/npm/dm/xunit-file.svg)](https://www.npmjs.com/package/xunit-file)

# Usage

```
npm install xunit-file --save-dev
```

Run mocha with `-R xunit-file` or `--reporter xunit-file`

The xunit.xml output is saved in `process.cwd()/xunit.xml` by default.

### Options

To change the output and activate terminal output, you can create a `config.json`, or use environment variables.

**config.json**
```
{
"file" : "${cwd}/xunit.xml",
"consoleOutput" : {
"suite" : true,
"test" : true,
"fail" : false
}
}
```

**environment variables**
```
$ XUNIT_FILE=output/xunit.xml mocha -R xunit-file // writes result to output/xunit.xml
$ LOG_XUNIT=true mocha -R xunit-file // activates terminal output
$ XUNIT_SILENT=true mocha -R xunit-file // disable all terminal output
```

Set XUNIT_LOG_ENV environment variable, if you want the output process and environment variables in the properties section of the xml file.

```
$ XUNIT_LOG_ENV=true mocha -R xunit-file
```

Add the following to the xml report.

```xml







...




```

**File Path Options**

The file path accepts a few custom tokens to allow creation of dynamic file names. This can be useful for multithreaded testing (such as using a Selenium Grid) or to keep multiple files by timestamp. Tokens are in the following format:

```
${tokenName: 'Token Data'}
```

The available tokens are `pid` to inject the process id, `cwd` to inject the current working directory, and `ts` or `timestamp` to inject a timestamp.

By default `ts` and `timestamp` use the [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, ex: `2016-03-31T07:27:48+00:00`. However, if you specify a custom format in the Token Data, the timestamp uses the [node dateformat](https://github.com/felixge/node-dateformat) library to output a string in that format.

A full example `config.json` is as follows:

```
{
"file": "${cwd}/${timestamp: 'MMDD-hhmm'}/xunit-${pid}.xml"
}
```

This would output something like `~/myProject/1217-1507/xunit-1234.xml`. This example would keep copies good for a year without collision, and group multithreaded results by test run.

Tokens can be used in either environment variables or a config.json. The default filepath is always `${cwd}/xunit.xml`.

# Credits
This reporter is just the original [xunit reporter](https://github.com/visionmedia/mocha/blob/master/lib/reporters/xunit.js) from mocha only writing the result in an xml file.

# LICENSE

MIT

# Sponsors

[](https://peerigon.com)