forked from getgauge/taiko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.test.js
67 lines (61 loc) · 1.86 KB
/
helper.test.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
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
const expect = chai.expect;
let { waitUntil } = require('../../lib/helper');
describe('Helper', () => {
describe('waitUntil', () => {
let callCount, maxCallCOunt;
const condition = async () => {
if (callCount === maxCallCOunt) {
return true;
}
callCount++;
return false;
};
beforeEach(() => {
callCount = 0;
maxCallCOunt = 3;
});
it('should retry for given time', async () => {
await waitUntil(condition, 1, 50);
expect(callCount).to.be.equal(3);
});
it('should fail after given time', async () => {
maxCallCOunt = 12;
await expect(waitUntil(condition, 10, 20)).to.be.eventually.rejectedWith(
'waiting failed: retryTimeout 20ms exceeded',
);
});
it('should fail with actual error if any after given time', async () => {
await expect(
waitUntil(
async () => {
await condition();
throw new Error('Actual error message.');
},
1,
50,
),
).to.be.eventually.rejectedWith('Actual error message.');
expect(callCount).to.be.equal(3);
});
it('should not retry on BrowserProcessCrashed error', async () => {
await expect(
waitUntil(
async () => {
await condition();
throw new Error('Browser process with pid 2045 exited with signal SIGTERM');
},
1,
20,
),
).to.be.eventually.rejectedWith('Browser process with pid 2045 exited with signal SIGTERM');
expect(callCount).to.be.equal(1);
});
it('should not evaluate condition when retryTimeout is not provided', async () => {
await waitUntil(condition, 1);
expect(callCount).to.be.equal(0);
});
});
});