# xunit-file

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

Latest version **2.0.1** (published 2023-02-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install xunit-file
pnpm add xunit-file
yarn add xunit-file
bun add xunit-file
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2023-02-01 |
| First published | 2012-08-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 12.0.0 |
| Dependencies | 2 |
| Unpacked size | 19.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 37 |
| Author | Matthias Jahn |
| Maintainers | thois, jhnns, meaku, peeri, matthaias, leomelzer, antosan, moritzjacobs, hpohlmeyer |
| Keywords | mocha, xunit, file, reporter |

## Links

- npm: https://www.npmjs.com/package/xunit-file
- Repository: https://github.com/peerigon/xunit-file
- Homepage: https://github.com/peerigon/xunit-file#readme
- Issues: https://github.com/peerigon/xunit-file/issues
- npm.io page: https://npm.io/package/xunit-file

## Dependencies (2)

- [mkdirp](https://npm.io/package/mkdirp.md) ^1.0.4
- [dateformat](https://npm.io/package/dateformat.md) ^4.6.2

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 2.0.1 (latest) — 2023-02-01
- 2.0.0 — 2021-11-24
- 1.0.0 — 2016-06-22
- 0.0.11 — 2016-06-11
- 0.0.10 — 2016-06-10
- 0.0.9 — 2015-10-31
- 0.0.8 — 2015-10-04
- 0.0.7 — 2015-08-18
- 0.0.6 — 2014-12-22
- 0.0.5 — 2013-10-17
- 0.0.4 — 2013-06-12
- 0.0.3 — 2013-03-18
- 0.0.2 — 2013-01-25
- 0.0.1 — 2012-08-17

## 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
<properties>
  <property name="process.arch" value="x64"/>
  <property name="process.platform" value="win32"/>
  <property name="process.memoryUsage" value="[ rss: '26570752', heapTotal: '17734144', heapUsed: '8982088']"/>
  <property name="process.cwd" value="D:\Dev\Demo\git\Demo\DemoApp\build\jsTest"/>
  <property name="process.execPath" value="D:\Dev\Demo\git\Demo\DemoApp\build\nodeJs\node-v0.11.10-windows-x64\bin\node.exe"/>
  <property name="process.version" value="v0.11.10"/>
  <property name="process.versions" value="[ http_parser: '2.2', node: '0.11.10', v8: '3.22.24.10', uv: '0.11.17', zlib: '1.2.3', modules: '13', openssl: '1.0.1e']"/>

  ...

  <property name="process.env.NODE_PATH" value="D:\Dev\Demo\git\Demo\DemoApp\build\jsTest\node_modules"/>
  <property name="process.env.SUITE_NAME" value="jsTest.myTest"/>
  <property name="process.env.XUNIT_FILE" value="D:\Dev\Demo\git\Demo\DemoApp\build\test-results\TEST-jsTest.myTest.xml"/>
  <property name="process.env.LOG_XUNIT" value="undefined"/>
</properties>
```

**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

[<img src="https://assets.peerigon.com/peerigon/logo/peerigon-logo-flat-spinat.png" width="150" />](https://peerigon.com)

---
_Source: https://npm.io/package/xunit-file · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
