-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
retries.spec.js
170 lines (147 loc) · 3.92 KB
/
retries.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
'use strict';
var assert = require('assert');
var helpers = require('./helpers');
var runJSON = helpers.runMochaJSON;
var args = [];
var bang = require('../../lib/reporters/base').symbols.bang;
describe('retries', function() {
it('are ran in correct order', function(done) {
helpers.runMocha(
'retries/hooks.fixture.js',
['--reporter', 'dot'],
function(err, res) {
var lines, expected;
if (err) {
done(err);
return;
}
lines = res.output
.split(helpers.SPLIT_DOT_REPORTER_REGEXP)
.map(function(line) {
return line.trim();
})
.filter(function(line) {
return line.length;
})
.slice(0, -1);
expected = [
'before',
'before each 0',
'TEST 0',
'after each 1',
'before each 1',
'TEST 1',
'after each 2',
'before each 2',
'TEST 2',
'after each 3',
'before each 3',
'TEST 3',
'after each 4',
'before each 4',
'TEST 4',
bang + 'after each 5',
'after'
];
expected.forEach(function(line, i) {
assert.strictEqual(lines[i], line);
});
assert.strictEqual(res.code, 1);
done();
}
);
});
it('should exit early if test passes', function(done) {
runJSON('retries/early-pass.fixture.js', args, function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have passed')
.and('to have passed test count', 2)
.and('to have failed test count', 0)
.and('to have retried test', 'should pass after 1 retry', 1);
done();
});
});
it('should let test override', function(done) {
runJSON('retries/nested.fixture.js', args, function(err, res) {
if (err) {
done(err);
return;
}
assert.strictEqual(res.stats.passes, 0);
assert.strictEqual(res.stats.failures, 1);
assert.strictEqual(res.stats.tests, 1);
assert.strictEqual(res.tests[0].currentRetry, 1);
assert.strictEqual(res.code, 1);
done();
});
});
it('should not hang w/ async test', function(done) {
helpers.runMocha(
'retries/async.fixture.js',
['--reporter', 'dot'],
function(err, res) {
var lines, expected;
if (err) {
done(err);
return;
}
lines = res.output
.split(helpers.SPLIT_DOT_REPORTER_REGEXP)
.map(function(line) {
return line.trim();
})
.filter(function(line) {
return line.length;
})
.slice(0, -1);
expected = [
'before',
'before each 0',
'TEST 0',
'after each 1',
'before each 1',
'TEST 1',
'after each 2',
'before each 2',
'TEST 2',
'after each 3',
'after'
];
expected.forEach(function(line, i) {
assert.strictEqual(lines[i], line);
});
assert.strictEqual(res.code, 0);
done();
}
);
});
it('should return current retry count out of total retry count', function(done) {
helpers.runMocha(
'retries/early-pass.fixture.js',
['--reporter', 'spec'],
function(err, res) {
var lines, expected;
if (err) {
done(err);
return;
}
lines = res.output
.split(helpers.SPLIT_DOT_REPORTER_REGEXP)
.map(function(line) {
return line.trim();
})
.filter(function(line) {
return line.length;
})
.slice(0, -1);
var retryPattern = /\(retry x\d+\)/;
var actual = lines[1].match(retryPattern)[0];
var expected = '(retry x1)';
assert.equal(actual, expected);
done();
}
);
});
});