This repository was archived by the owner on Sep 21, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathstats.js
More file actions
100 lines (81 loc) · 2.67 KB
/
Copy pathstats.js
File metadata and controls
100 lines (81 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
AEF0
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'use strict';
const EventEmitter = require('events').EventEmitter;
const inherit = require('inherit');
const Stats = require('lib/stats');
const RunnerEvents = require('lib/constants/runner-events');
describe('stats', () => {
let stats;
beforeEach(() => {
stats = new Stats();
});
it('should return \'undefined\' before adding keys', () => {
assert.isUndefined(stats.get('counter'));
});
it('should allow to add new key', () => {
stats.add('counter');
assert.equal(stats.get('counter'), 1);
});
it('should increment existing keys', () => {
stats.add('counter');
stats.add('counter');
assert.equal(stats.get('counter'), 2);
});
it('should return all full stat', () => {
stats.add('counter');
stats.add('counter');
stats.add('counter');
stats.add('counter2');
stats.add('counter3');
stats.add('counter3');
assert.deepEqual(stats.get(), {
counter: 3,
counter2: 1,
counter3: 2
});
});
});
describe('stats listener', () => {
let stats;
let Runner = inherit(EventEmitter, {});
let runner;
beforeEach(() => {
runner = new Runner();
stats = new Stats(runner);
});
it('should return undefined before triggering any events', () => {
assert.isUndefined(stats.get('total'));
});
it('should count on beginState event', () => {
runner.emit(RunnerEvents.BEGIN_STATE);
assert.equal(stats.get('total'), 1);
});
it('should count on skipState event', () => {
runner.emit(RunnerEvents.SKIP_STATE);
assert.equal(stats.get('total'), 1);
assert.equal(stats.get('skipped'), 1);
});
it('should count on warning event', () => {
runner.emit(RunnerEvents.WARNING);
assert.equal(stats.get('warned'), 1);
});
it('should count on error event', () => {
runner.emit(RunnerEvents.ERROR);
assert.equal(stats.get('errored'), 1);
});
it('should count on updated images', () => {
runner.emit(RunnerEvents.UPDATE_RESULT, {updated: true});
assert.equal(stats.get('updated'), 1);
});
it('should count on passed images', () => {
runner.emit(RunnerEvents.UPDATE_RESULT, {updated: false});
assert.equal(stats.get('passed'), 1);
});
it('should count test passed', () => {
runner.emit(RunnerEvents.TEST_RESULT, {equal: true});
assert.equal(stats.get('passed'), 1);
});
it('should count test failed', () => {
runner.emit(RunnerEvents.TEST_RESULT, {equal: false});
assert.equal(stats.get('failed'), 1);
});
});