-
Notifications
You must be signed in to change notification settings - Fork 12
/
test-cli.js
183 lines (163 loc) · 4.49 KB
/
test-cli.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* jshint unused:true */
'use strict';
var exec = require('child_process').exec;
var eachExec = require('each-exec');
var test = require('tape');
var pkg = require('./package.json');
var isogram = require('./');
var bin = 'node ' + pkg.bin + ' ';
test('"isogram" command', function(t) {
t.plan(22);
exec(bin, function(err, stdout, stderr) {
t.deepEqual(
[err, stdout, stderr],
[null, isogram() + '\n', ''],
'should generate Google Analytics code.'
);
});
var expected = isogram({
id: '01234-5',
domain: 'foo.org',
globalName: 'bar',
minify: true,
singleQuotes: false,
color: true
}) + '\n';
eachExec([
bin + '--id 01234-5 --domain foo.org --global bar --minify --double --color',
bin + '-i 01234-5 -d foo.org -g bar -m -w -c'
], function(err, stdouts, stderrs) {
t.deepEqual(
[err, stdouts[0], stderrs[0]],
[null, expected, ''],
'should reflect option flags to the result.'
);
t.equal(
stdouts[0],
stdouts[1],
'should use short flags as aliases.'
);
});
exec(bin + '--no-color', function(err, stdout, stderr) {
t.deepEqual(
[err, stdout, stderr],
[null, isogram({color: false}) + '\n', ''],
'should omit ANSI colors from the result, using --no-color flag.'
);
});
exec(bin + '--no-track', function(err, stdout, stderr) {
t.deepEqual(
[err, stdout, stderr],
[null, isogram({track: false}) + '\n', ''],
'should omit `create` and `send` commands if using --no-track flag.'
);
});
exec(bin + '-s', function(err, stdout, stderr) {
t.deepEqual(
[err, stdout, stderr],
[null, isogram({scriptTag: true}) + '\n', ''],
'should use -s as an alias of --script-tag.'
);
});
exec(bin + '--script-tag', function(err, stdout, stderr) {
t.deepEqual(
[err, stdout, stderr],
[null, isogram({scriptTag: true}) + '\n', ''],
'should add <script> tag if using --script flag.'
);
});
eachExec([
bin + '--version',
bin + '-v'
], function(err, stdouts, stderrs) {
t.deepEqual(
[err, stdouts[0], stderrs[0]],
[null, pkg.version + '\n', ''],
'should print version number using --version flag.'
);
t.equal(
stdouts[0],
stdouts[1],
'should use -v as an alias of --version.'
);
});
eachExec([
bin + '--help',
bin + '-h'
], function(err, stdouts, stderrs) {
t.ok(
/Usage/.test(stdouts[0]),
'should print usage information using --help flag.'
);
t.deepEqual(
[err, stderrs[0]],
[null, ''],
'should print nothing to stderr when --help flag is enabled.'
);
t.equal(
stdouts[0],
stdouts[1],
'should use -h as an alias of --help.'
);
});
exec(bin + '12abcd', function(err, stdout, stderr) {
t.strictEqual(
err.code,
1,
'should exit with code 1 when it takes invalid characters.'
);
t.equal(
stderr,
'"1" and "2" cannot be used as JavaScript parameter names.\n',
'should print error message when it takes invalid characters.'
);
});
exec(bin + 'aabbcd', function(err, stdout, stderr) {
t.strictEqual(
err.code,
1,
'should exit with code 1 when it takes duplicated characters.'
);
t.equal(
stderr,
'"a" and "b" are duplicated.\n',
'should print error message when it takes duplicated characters.'
);
});
exec(bin + 'ab', function(err, stdout, stderr) {
t.strictEqual(
err.code,
1,
'should exit with code 1 when it takes less than 3 characters.'
);
t.equal(
stderr,
'Number of characters must be no fewer than 3 and no greater than 7.\n',
'should print error message when it takes less than 3 characters.'
);
});
exec(bin + 'abcdefgh', function(err, stdout, stderr) {
t.strictEqual(
err.code,
1,
'should exit with code 1 when it takes more than 7 characters.'
);
t.equal(
stderr,
'Number of characters must be no fewer than 3 and no greater than 7.\n',
'should print error message when it takes more than 7 characters.'
);
});
exec(bin + '--global ↓', function(err, stdout, stderr) {
t.strictEqual(
err.code,
1,
'should exit with code 1 when --global flag takes an invalid name.'
);
t.equal(
stderr,
'↓ cannot be used as a global variable name.\n',
'should print error message when --global flag takes an invalid name.'
);
});
});