-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtests.js
66 lines (55 loc) · 1.31 KB
/
tests.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
'use strict';
const assert = require('node:assert');
const { api } = require('./client.js');
const runner = require('./runner.js');
const server = require('./server.js');
// Tests
const testStart = (next) => {
const timer = setTimeout(() => {
const err = new Error('Can not start counter');
assert.fail(err);
next(err);
}, 200);
const req = api.startCounter('name1', 100);
assert.ok(req);
req.then((res) => {
assert.strictEqual(res, 'ok');
clearTimeout(timer);
setTimeout(next, 150);
});
};
const testStop = (next) => {
const timer = setTimeout(() => {
const err = new Error('Can not stop counter');
assert.fail(err);
next(err);
}, 200);
const req = api.stopCounter('name1');
assert.ok(req);
req.then((res) => {
assert.strictEqual(res, 'ok');
clearTimeout(timer);
setTimeout(next, 150);
});
};
const testStopUnknown = async (next) => {
const timer = setTimeout(() => {
const err = new Error('Can not stop counter');
assert.fail(err);
next(err);
}, 200);
const res = await api.stopCounter('name2');
assert.strictEqual(res, 'not found');
clearTimeout(timer);
setTimeout(next, 150);
};
// Execute tests
const tests = [
testStart,
testStop,
testStopUnknown,
];
(async () => {
await server.start();
runner.start(tests);
})();