File: test.js

package info (click to toggle)
node-cli-cursor 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 124 kB
  • ctags: 14
  • sloc: makefile: 4; sh: 2
file content (58 lines) | stat: -rw-r--r-- 1,291 bytes parent folder | download
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
var childProcess = require('child_process');
var assert = require('assert');
var cliCursor = require('./');

const write = process.stdout.write;
const SHOW = '\u001b[?25h';
const HIDE = '\u001b[?25l';

function getStdout(fn) {
	var ret = '';

	process.stdout.setEncoding('utf8');
	process.stdout.write = str => {
		ret += str;
	};

	fn();
	process.stdout.write = write;
	return ret;
}

test('show', function() {
	assert.equal(getStdout(cliCursor.show), SHOW);
});

test('hide', function() {
	assert.equal(getStdout(cliCursor.hide), HIDE);
});

test('toggle', function() {
	cliCursor.hide();
	assert.equal(getStdout(cliCursor.toggle), SHOW);
});

test('toggle 2', function() {
	cliCursor.show();
	assert.equal(getStdout(cliCursor.toggle), HIDE);
});

test('toggle force', function() {
	cliCursor.show();
	assert.equal(getStdout(cliCursor.toggle.bind(null, true)), SHOW);
});

test('toggle force 2', function() {
	cliCursor.hide();
	assert.equal(getStdout(cliCursor.toggle.bind(null, true)), SHOW);
});

test('toggle force 3', function() {
	cliCursor.show();
	assert.equal(getStdout(cliCursor.toggle.bind(null, false)), HIDE);
});

// used to fail, see sindresorhus/log-update#2
test('require', function() {
	assert.equal(childProcess.execSync('nodejs index.js', {encoding: 'utf8'}), '');
});