-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest.js
61 lines (48 loc) · 1.24 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
51
52
53
54
55
56
57
58
59
60
61
import process from 'node:process';
import childProcess from 'node:child_process';
import test from 'ava';
import cliCursor from './index.js';
const {stderr: {write}} = process;
const SHOW = '\u001B[?25h';
const HIDE = '\u001B[?25l';
process.stderr.isTTY = true;
function getStderr(function_) {
let result = '';
process.stderr.setEncoding('utf8');
process.stderr.write = string => {
result += string;
};
function_();
process.stderr.write = write;
return result;
}
test('show', t => {
t.is(getStderr(cliCursor.show), SHOW);
});
test('hide', t => {
t.is(getStderr(cliCursor.hide), HIDE);
});
test('toggle', t => {
cliCursor.hide();
t.is(getStderr(cliCursor.toggle), SHOW);
});
test('toggle 2', t => {
cliCursor.show();
t.is(getStderr(cliCursor.toggle), HIDE);
});
test('toggle force', t => {
cliCursor.show();
t.is(getStderr(cliCursor.toggle.bind(null, true)), SHOW);
});
test('toggle force 2', t => {
cliCursor.hide();
t.is(getStderr(cliCursor.toggle.bind(null, true)), SHOW);
});
test('toggle force 3', t => {
cliCursor.show();
t.is(getStderr(cliCursor.toggle.bind(null, false)), HIDE);
});
// Used to fail, see sindresorhus/log-update#2
test('require', t => {
t.is(childProcess.execSync('node index.js', {encoding: 'utf8'}), '');
});