-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzolt.spec.js
50 lines (37 loc) · 1.23 KB
/
zolt.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
import test from 'ava';
import { Zolt } from './zolt';
let writeOutput = '';
const writeStub = text => {
writeOutput += text;
};
test.beforeEach(() => {
writeOutput = '';
process.stdout.write = writeStub;
});
test.serial('start method should initiate spinner and update frame', async t => {
Zolt.start();
t.truthy(Zolt.spinnerInstance);
t.is(Zolt.spinnerInstance.currentFrame, 0);
await new Promise(resolve => setTimeout(resolve, 100));
t.is(Zolt.spinnerInstance.currentFrame, 1);
Zolt.stop();
});
test.serial('stop method should stop the spinner and clear the line', async t => {
Zolt.start('bars', 'red', 'Processing');
await new Promise(resolve => setTimeout(resolve, 200));
Zolt.stop();
t.deepEqual(Zolt.spinnerInstance, undefined);
t.true(writeOutput.includes('\r\x1b[K'));
});
test.serial('stop callback exuction', async t => {
let cb = null;
Zolt.start();
await new Promise(resolve => setTimeout(resolve, 100));
Zolt.stop(() => cb = true);
t.deepEqual(cb, true);
})
test.serial('getColorCode method should return correct ANSI color code', t => {
const spinner = new Zolt();
t.is(spinner.getColorCode('green'), '\x1b[32m');
t.is(spinner.getColorCode('invalidColor'), '\x1b[0m');
});