-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest.js
163 lines (136 loc) · 3.75 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
'use strict';
require('mocha');
var isCI = process.env.TRAVIS || process.env.APPVEYOR || process.env.CI;
var assert = require('assert');
var utils = require('./utils');
var size = require('./');
var tty = require('tty');
function override(obj) {
var getWindowSize = obj.getWindowSize;
var columns = obj.columns;
var rows = obj.rows;
obj.getWindowSize = null;
obj.columns = null;
obj.rows = null;
return function() {
obj.getWindowSize = getWindowSize;
obj.columns = columns;
obj.rows = rows;
};
}
describe('window-size', function() {
it('should return an object with width and height', function() {
if (!process.env.APPVEYOR) {
assert.equal(typeof size.width, 'number');
assert.equal(typeof size.height, 'number');
}
});
it('should expose a `.get` method to get up-to-date size', function() {
if (!process.env.APPVEYOR) {
var s = size.get();
assert.equal(typeof s.width, 'number');
assert.equal(typeof s.height, 'number');
}
});
it('should get size from process.stdout', function() {
if (!process.env.APPVEYOR) {
var count = 0;
var restore = override(process.stdout);
process.stdout.getWindowSize = function() {
count++;
};
size.get();
restore();
assert.equal(count, 1);
}
});
it('should get size from process.stderr', function() {
if (!process.env.APPVEYOR) {
var restoreOut = override(process.stdout);
var restoreErr = override(process.stderr);
var count = 0;
process.stderr.getWindowSize = function() {
count++;
};
size.get();
restoreOut();
restoreErr();
assert.equal(count, 1);
}
});
it('should get size from process.env', function() {
if (!process.env.APPVEYOR) {
process.env.COLUMNS = 80;
process.env.ROWS = 25;
var s = size.env();
assert(s);
assert.equal(s.width, 80);
assert.equal(s.height, 25);
process.env.COLUMNS = null;
process.env.ROWS = null;
}
});
it('should get size from tty', function() {
if (!process.env.APPVEYOR) {
var restoreOut = override(process.stdout);
var restoreErr = override(process.stderr);
var restoreTty = override(tty);
var count = 0;
tty.getWindowSize = function() {
count++;
};
size.get();
restoreOut();
restoreErr();
restoreTty();
assert.equal(count, 1);
}
});
it('should get size from tput', function() {
if (!isCI) {
var s = size.tput();
assert(s);
assert.equal(typeof s.width, 'number');
assert.equal(typeof s.height, 'number');
}
});
describe('utils', function() {
it('should expose a `.get` method to get up-to-date size', function() {
var s = utils.get();
if (process.env.APPVEYOR) {
assert.equal(typeof s, 'undefined');
} else {
assert.equal(typeof s.width, 'number');
assert.equal(typeof s.height, 'number');
}
});
it('should get size from process.env', function() {
process.env.COLUMNS = 80;
process.env.ROWS = 25;
var s = utils.env();
assert(s);
assert.equal(s.width, 80);
assert.equal(s.height, 25);
process.env.COLUMNS = null;
process.env.ROWS = null;
});
it('should get size from tty', function() {
var restoreTty = override(tty);
var count = 0;
tty.getWindowSize = function() {
count++;
};
utils.tty({});
restoreTty();
assert.equal(count, 1);
});
it('should get size from tput', function() {
if (!isCI) {
var s = utils.tput();
assert(s);
assert.equal(typeof s.width, 'number');
assert.equal(typeof s.height, 'number');
}
});
});
});