forked from emmikkelsen/node-lectio-til-ics
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
50 lines (41 loc) · 1.12 KB
/
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
/* eslint-disable no-console*/
const URL = 'http://icanhazip.com';
const SCHOOL = '590';
import browser from './browser';
import retry from './retry';
const { exit, stderr, stdout } = process;
(async () => {
try {
const page = await browser.fetch(`${URL}`, `${SCHOOL}`);
stdout.write(page);
exit(0);
} catch (error) {
stderr.write(error.message);
exit(1);
}
const expectedResult = 'yay'
const fnSuccess = () => expectedResult;
const result = await retry(fnSuccess);
if (result !== expectedResult) {
stderr.write(`expected result ${expectedResult}, got ${result}`);
exit(1);
}
let tryTimes = 0;
const expectedRetries = 3;
try {
const fnFail = () => {
tryTimes ++;
throw new Error('some error');
}
await retry(fnFail, { maxTries: expectedRetries });
} catch (error) {
if (error.message !== `Gave up after ${expectedRetries} attempts`) {
stderr.write(error.message);
exit(1);
}
if (tryTimes !== expectedRetries) {
stderr.write(`expected to try ${expectedRetries} times, actually tried ${tryTimes} times`);
exit(1);
}
}
})();