Giter VIP home page Giter VIP logo

xunit-file's Introduction

xunit-file

Basically the same reporter as mocha's xunit reporter, but writes the output to a 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.

<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 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 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 from mocha only writing the result in an xml file.

LICENSE

MIT

Sponsors

xunit-file's People

Contributors

brycekahle avatar davebrown avatar epall avatar ghazal-karami avatar grandvizier avatar iamfromspace avatar jhnns avatar jonnyreeves avatar jugend avatar leomelzer avatar markherhold avatar matthaias avatar meaku avatar mlucool avatar subeeshcbabu avatar whambamdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xunit-file's Issues

path to config.js should not be module-relative

Please give me an example where to put my config.js to.

Looking at your source, the path seems to be module-realtive hard coded t.i. ../config.json. So it only reads your distributed config.json, but never mine ๐Ÿ˜•

Use semantic versioning

Hey @matthaias ,

thanks for your great module ๐Ÿ‘
The only thing that bothers me a bit is that it still is in the 0.0.x version range, so the only way we can stay updated in a larger amount of projects is to use 0.0.x in the package.json. That's a bit of a surprise bag then ๐Ÿ˜„ Maybe we get bugfixes, maybe we get major breaking changes. Did you consider using the semantic versioning specification for your releases?

Regards,
Ben

make it possible to create report file names as timestamp

If i do not want to overwrite the file after every run then at the moment there is no good way to solve the problem. My suggestion is to add new key- value to json that defines if I wanna use timestamp file names or not.

json should have :

{
    "file" : "xunit.xml",
    "timestamp":true,
    "consoleOutput" : {
      "suite" : true,
      "test" : true,
      "fail" : false
    }
}

and code change :

/**
 * Module dependencies.
 */
var Date = global.Date
    , setTimeout = global.setTimeout
    , setInterval = global.setInterval
    , clearTimeout = global.clearTimeout
    , clearInterval = global.clearInterval;

var mocha = require("mocha")
  , Base = mocha.reporters.Base
  , utils = mocha.utils
  , escape = utils.escape
  , config = require("../config.json")
  , fs = require("fs")
  , path = require("path")
  , mkdirp = require("mkdirp")
  , filePath = config.timestamp === true ? process.cwd() + "/"+(new Date()).getTime()+".xml" : process.env.XUNIT_FILE || config.file ||   process.cwd() + "/xunit.xml"
  , consoleOutput = config.consoleOutput || {};

Propose: Making xunit-file compatible with grunt-mocha-test

Hi,

It should be nice if I can use this lib the same as some other reporters.
Just pass the path to the file as optional parameter, rather than environment variable.

mochaTest: {
'xunit-file-report': {
options: {
reporter: 'xunit-file',
captureFile: 'test/xunit.xml'
},
src: ['test/*/-spec.js']
},...

Thanks in advance!

Kind regards

Kristof

Cannot find module 'xunit-file'

@peerigon I'm getting this problem with mocha 1.9.0 & xunit-file 0.0.3 both installed locally to my project (works when both are installed globally though)...
Any clue?

se@picabo:~/dev/controller-app-bootstrapper$ mocha --reporter xunit-file

module.js:340
    throw err;
          ^
Error: Cannot find module 'xunit-file'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Mocha.reporter (/usr/lib/node_modules/mocha/lib/mocha.js:117:24)
    at Object.<anonymous> (/usr/lib/node_modules/mocha/bin/_mocha:177:7)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

Proper config.json entry

Hi,

You mention in your README that xunit-file will use the file specified in the config.js. 1. Where does the config.js file live and 2. What would the exact property name be?

Thanks in advance

Support for outputs to multiple files?

How can I configure xunit-file to write to different files for different tests?

Currently, I have a project setup in which I have one test folder for unit tests and one itest folder for integration tests. First, the unit tests are executed directly against the source code, if successful the application is packaged and deployed, and then integration tests are executed against the deployed app. I have two npm scripts in my package.json file:

"scripts": {
    "test": "mocha --recursive -R xunit-file",
    "itest": "mocha --recursive itest -R xunit-file"
}

The problem is when I execute npm run itest it will overwrite the result in xunit.xml generated by npm test.

With the default xunit reporter it is possible to use > to redirect the output to different files like:

"scripts": {
    "test": "mocha --recursive -R xunit > xunit-test.xml",
    "itest": "mocha --recursive itest -R xunit > xunit-itest.xml"
}

The problem with this setup is that the default xunit reporter also include printouts from console.log(), which means that the resulting files not only contain valid xml but also log statements.

Compatibility with gulp-mocha

Hey, I can't seem to get this to load correctly inside of gulp-mocha, I think because my copy of mocha is "hidden" inside of gulp-mocha, so when this one runs require("mocha") it blows up. (If that's the cause, then npm v3.x will fix it, but it's still worth considering for older versions.)

Also, mocha currently reports the wrong error message, I filed mochajs/mocha#1952 to address that.

Error: invalid reporter "xunit-file"

I have installed it using npm install xunit-file -g

and even attempted to copy the file xunit-file.js from /usr/local/lib/node_modules/xunit-file/lib/xunit-file.js into /usr/local/lib/node_modules/mocha/lib/reporters/xunit-file.js"

the strange thing is that one project is currently runnig OK and not complaining about the missing reporter

this is happening on a second parallel test run of some other branch

/usr/local/bin/mocha -t 99999 --recursive -R xunit-file ./test/login

/usr/local/lib/node_modules/mocha/lib/mocha.js:146
    if (!_reporter) throw new Error('invalid reporter "' + reporter + '"');
                          ^
Error: invalid reporter "xunit-file"
    at Mocha.reporter (/usr/local/lib/node_modules/mocha/lib/mocha.js:146:27)
    at Object.<anonymous> (/usr/local/lib/node_modules/mocha/bin/_mocha:196:7)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.