1 | mocha-multi
|
2 | ===========
|
3 |
|
4 | A bit of a hack to get multiple reporters working with mocha
|
5 |
|
6 | [![Build Status](https://travis-ci.org/glenjamin/mocha-multi.png?branch=master)](https://travis-ci.org/glenjamin/mocha-multi)
|
7 | [![NPM version](https://badge.fury.io/js/mocha-multi.png)](http://badge.fury.io/js/mocha-multi)
|
8 |
|
9 | Usage
|
10 | -----
|
11 |
|
12 | npm install mocha-multi --save-dev
|
13 | mocha --reporter mocha-multi
|
14 |
|
15 | Choosing Reporters
|
16 | ------------------
|
17 |
|
18 | Set an environment variable called `multi` to specify the desired reporters.
|
19 | Reporters are listed as whitespace separated type=destination pairs.
|
20 |
|
21 | ```bash
|
22 | multi='dot=- xunit=file.xml doc=docs.html' mocha -R mocha-multi
|
23 | ```
|
24 |
|
25 | The special value of `-` (hyphen) for destination uses normal stdout/stderr.
|
26 |
|
27 | Using mocha-multi programmatically
|
28 | ----------------------------------
|
29 |
|
30 | Specify the desired reporters (and their options) by passing reporterOptions to the Mocha contructor
|
31 |
|
32 | for example: this is the equivalent of multi='spec=- Progress=/tmp/mocha-multi.Progress.out', with the addition of passing the verbose:true option to the Progress reporter
|
33 | ```sh
|
34 | var reporterOptions={
|
35 | Progress:{
|
36 | stdout:"/tmp/mocha-multi.Progress.out",
|
37 | options: {
|
38 | verbose: true
|
39 | }
|
40 | },
|
41 | spec: {
|
42 | stdout:"-"
|
43 | }
|
44 | };
|
45 |
|
46 | var mocha = new Mocha({
|
47 | ui: 'bdd',
|
48 | reporter: "mocha-multi",
|
49 | reporterOptions:reporterOptions
|
50 | });
|
51 | mocha.addFile("test/dummy-spec.js");
|
52 | mocha.run(function onRun(failures){
|
53 | console.log(failures);
|
54 | });
|
55 | ```
|
56 | The options will be passed as the second argument to the reporter constructor
|
57 |
|
58 | How it works
|
59 | ------------
|
60 |
|
61 | A big hack that keeps changing the value of process.stdout and process.stderr whenever a reporter is doing its thing.
|
62 |
|
63 | Seriously?
|
64 | ----------
|
65 |
|
66 | Yeah, Sorry!
|
67 |
|
68 | All the hacks
|
69 | -------------
|
70 |
|
71 | This is very hacky, specifically:
|
72 |
|
73 | * The `process` and `console` objects get their internal state messed with
|
74 | * `process.exit` is hacked to wait for streams to finish writing
|
75 | * Only works if reporters queue writes synchronously in event handlers
|
76 |
|
77 | Could this be a bit less hacky?
|
78 | -------------------------------
|
79 |
|
80 | * Now that visionmedia/mocha#1059 is released the process.exit hack could be tidier
|
81 |
|
82 | * If visionmedia/mocha#1061 is accepted upstream, I only need to hijack stdout, and can leave stderr alone
|
83 |
|
84 | * Having each reporter run in a child process would make it eaiser to capture their streams, but might lead to other issues
|
85 |
|
86 | TODO
|
87 | ----
|
88 |
|
89 | * Update hack now that visionmedia/mocha#1059 is merged
|
90 | * Add tests for coverage reports
|
91 | * Add tests which produce multiple reports at once
|
92 | * Add test for help text
|
93 | * Add test that uses --no-exit
|
94 | * Add test that doesn't use _mocha (maybe not?)
|