1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | var constants = require('./runner').constants;
|
9 | var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
10 | var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
11 | var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
|
12 | var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
13 | var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
14 | var EVENT_RUN_END = constants.EVENT_RUN_END;
|
15 | var EVENT_TEST_END = constants.EVENT_TEST_END;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | var Date = global.Date;
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | function createStatsCollector(runner) {
|
42 | |
43 |
|
44 |
|
45 | var stats = {
|
46 | suites: 0,
|
47 | tests: 0,
|
48 | passes: 0,
|
49 | pending: 0,
|
50 | failures: 0
|
51 | };
|
52 |
|
53 | if (!runner) {
|
54 | throw new TypeError('Missing runner argument');
|
55 | }
|
56 |
|
57 | runner.stats = stats;
|
58 |
|
59 | runner.once(EVENT_RUN_BEGIN, function() {
|
60 | stats.start = new Date();
|
61 | });
|
62 | runner.on(EVENT_SUITE_BEGIN, function(suite) {
|
63 | suite.root || stats.suites++;
|
64 | });
|
65 | runner.on(EVENT_TEST_PASS, function() {
|
66 | stats.passes++;
|
67 | });
|
68 | runner.on(EVENT_TEST_FAIL, function() {
|
69 | stats.failures++;
|
70 | });
|
71 | runner.on(EVENT_TEST_PENDING, function() {
|
72 | stats.pending++;
|
73 | });
|
74 | runner.on(EVENT_TEST_END, function() {
|
75 | stats.tests++;
|
76 | });
|
77 | runner.once(EVENT_RUN_END, function() {
|
78 | stats.end = new Date();
|
79 | stats.duration = stats.end - stats.start;
|
80 | });
|
81 | }
|
82 |
|
83 | module.exports = createStatsCollector;
|