Last change
on this file was
484,
checked in by hendrikvanantwerpen, 11 years ago
|
Commit node_modules, to make checkouts and builds more deterministic.
|
File size:
1.1 KB
|
Line | |
---|
1 | |
---|
2 | /** |
---|
3 | * Module dependencies. |
---|
4 | */ |
---|
5 | |
---|
6 | var Base = require('./base') |
---|
7 | , cursor = Base.cursor |
---|
8 | , color = Base.color; |
---|
9 | |
---|
10 | /** |
---|
11 | * Expose `JSON`. |
---|
12 | */ |
---|
13 | |
---|
14 | exports = module.exports = JSONReporter; |
---|
15 | |
---|
16 | /** |
---|
17 | * Initialize a new `JSON` reporter. |
---|
18 | * |
---|
19 | * @param {Runner} runner |
---|
20 | * @api public |
---|
21 | */ |
---|
22 | |
---|
23 | function JSONReporter(runner) { |
---|
24 | var self = this; |
---|
25 | Base.call(this, runner); |
---|
26 | |
---|
27 | var tests = [] |
---|
28 | , failures = [] |
---|
29 | , passes = []; |
---|
30 | |
---|
31 | runner.on('test end', function(test){ |
---|
32 | tests.push(test); |
---|
33 | }); |
---|
34 | |
---|
35 | runner.on('pass', function(test){ |
---|
36 | passes.push(test); |
---|
37 | }); |
---|
38 | |
---|
39 | runner.on('fail', function(test){ |
---|
40 | failures.push(test); |
---|
41 | }); |
---|
42 | |
---|
43 | runner.on('end', function(){ |
---|
44 | var obj = { |
---|
45 | stats: self.stats |
---|
46 | , tests: tests.map(clean) |
---|
47 | , failures: failures.map(clean) |
---|
48 | , passes: passes.map(clean) |
---|
49 | }; |
---|
50 | |
---|
51 | process.stdout.write(JSON.stringify(obj, null, 2)); |
---|
52 | }); |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * Return a plain-object representation of `test` |
---|
57 | * free of cyclic properties etc. |
---|
58 | * |
---|
59 | * @param {Object} test |
---|
60 | * @return {Object} |
---|
61 | * @api private |
---|
62 | */ |
---|
63 | |
---|
64 | function clean(test) { |
---|
65 | return { |
---|
66 | title: test.title |
---|
67 | , fullTitle: test.fullTitle() |
---|
68 | , duration: test.duration |
---|
69 | } |
---|
70 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.