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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303 | 1
77
46
4
10
4
3
42
77
148
148
1
1
1
1
1
2
2
2
2
1
1
1
1
1
4
4
4
3
1
3
8
8
4
4
3
1
3
5
5
4
1
4
4
4
3
1
3
3
3
4
4
2
2
2
1
1
2
6
6
5
4
4
1
5
5
4
1
1
4
7
7
5
7
4
4
3
3
2
2
4
4
3
1
3
8
8
7
1
7
2
2
7
7
6
5
7
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
6
6
3
3
2
2
1
1
1
1
47
1
1
1
46
68
2
68
4
3
4
3
2
67
7
17
17
15
17
6
17
67
1
| var path = require('path'),
fs = require('fs'),
glob = require('glob'),
util = require('./index'),
log = require('./log'),
VERSION = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8')).version,
parse = function(args) {
var options = {
color: true,
port: 7000,
'phantom-bin': 'phantomjs', // relies on PATH
coverageWarn: 80,
concurrent: 15,
paths: [],
outtype: 'tap',
silent: false,
run: true,
quiet: false,
debug: false,
console: false,
exitOnFail: false,
istanbulReport: false,
sourceFilePrefix: false,
coverageFileName: false,
combo: []
}, newPath, paths, a, p, t, v, concurrent, coverageFileName, sourceFilePrefix,
phantom, stat,
getPaths = function(opt) {
if (process.platform === 'win32' && !options.suffix && !options.prefix && !options.server) { //If options.suffix it's probably a URL
var g = glob.sync(opt, {
cwd: process.cwd()
}).map(function (filepath) {
return path.relative(process.cwd(), filepath); //phantomjs won't "request" relative resources for absolute Windows paths
});
if (g && g.length) {
options.paths = [].concat(options.paths, g);
}
} else {
//shell exploded paths here
options.paths.push(opt);
}
};
while (args.length > 0) {
v = args.shift();
switch (v) {
case "--combo":
p = args.shift().split(':');
options.combo.push({
root: p[1],
route: p[0]
});
break;
case "--debug":
options.debug = true;
break;
case "--console":
options.console = true;
break;
case "--coverdir":
p = args.shift();
if (p) {
options.coverdir = path.resolve(p);
} else {
throw("--coverdir requires an argument");
}
break;
case "--no-color":
options.color = false;
break;
case "--coverage-warn":
a = args.shift();
p = parseInt(a, 10);
if (!isNaN(p)) {
options.coverageWarn = p;
} else {
throw('--coverage-warn requires a number argument');
}
break;
case "--coverage":
options.coverage = true;
break;
case "-co":
case "--coverageFileName":
coverageFileName = args.shift();
if (coverageFileName) {
options.coverageFileName = coverageFileName;
} else {
throw("-co requires an argument");
}
break;
case "-sp":
case "--sourceFilePrefix":
sourceFilePrefix = args.shift();
if (sourceFilePrefix) {
options.sourceFilePrefix = sourceFilePrefix;
} else {
throw("-sp requires an argument");
}
break;
case "--istanbul-report":
p = args.shift();
if (p) {
options.istanbulReport = p;
} else {
throw("Istanbul report needs a path");
}
break;
case "--no-run":
options.run = false;
break;
case "--server":
options.server = process.cwd();
break;
case "--port":
a = args.shift();
p = parseInt(a, 10);
if (!isNaN(p)) {
options.port = p;
} else {
args.unshift(a);
}
break;
case "--phantom-bin":
phantom = args.shift();
if (phantom) {
// allows "path/to/bin/" and "path/to/bin/phantomjs"
if (util.existsSync(phantom)) {
stat = fs.statSync(phantom);
if (stat && stat.isDirectory()) {
phantom = path.join(phantom, 'phantomjs');
}
}
// always make it an absolute path
phantom = path.resolve(phantom);
// make extra sure that the binary exists
if (util.existsSync(phantom)) {
options['phantom-bin'] = phantom;
} else {
throw "Custom phantomjs binary could not be found! (" + phantom + ")";
}
} else {
throw "--phantom-bin requires a path";
}
break;
case "-t":
case "--timeout":
t = parseInt(args.shift(), 10);
if (!isNaN(t)) {
options.timeout = t;
}
break;
case "-i":
case "--import":
options['import'] = args.shift();
break;
case "-s":
case "--silent":
options.silent = true;
break;
case "-q":
case "--quiet":
options.quiet = true;
break;
case "-S":
case "--suffix":
p = args.shift();
if (p) {
options.suffix = p;
} else {
throw('-S requires an argument');
}
break;
case "-p":
case "--prefix":
p = args.shift();
if (p) {
options.prefix = p;
} else {
throw('-p requires an argument');
}
break;
case "-f":
case "--fail":
options.exitOnFail = true;
break;
case "-c":
case "--concurrent":
concurrent = parseInt(args.shift(), 10);
if (!isNaN(concurrent)) {
if (concurrent > 1) {
options.concurrent = concurrent;
}
}
break;
case "-h":
case "--help":
/*jshint maxlen: 200*/
util.log('Grover is a YUITest wrapper to run tests in PhantomJS');
log.log('Version ' + VERSION);
log.log('');
log.log('grover <paths to yuitest html files>');
log.log(' -v, --version Print version');
log.log(' -h, --help Print this stuff');
log.log(' -s, --silent Print no output, only use exit code');
log.log(' -q, --quiet Only print errors and use exit code');
log.log(' -f, --fail Fail on first error');
log.log(' -c, --concurrent Number of tests to run concurrently, default: 15');
log.log(' -t, --timeout Specify a timeout (in seconds) for a test file to be considered as failed.');
log.log(' -i, --import <path to js file> - Require this file and use the exports (array)');
log.log(' as the list of files to process.');
log.log(' -p, --prefix <string> String to prefix to all urls (for dynamic server names)');
log.log(' -S, --suffix <string> String to add to the end of all urls (for dynamic server names)');
log.log(' -o, --outfile <path to export file>');
log.log(' You can specify an export type with the following:');
log.log(' --tap TAP export (default)');
log.log(' --xml XML export');
log.log(' --json JSON export');
log.log(' --junit JUnit XML export');
log.log(' --server Starts a static file server in the CWD, tests should be relative to this directory');
log.log(' --port <Number> The port to start the server on');
log.log(' --phantom-bin <path to phantomjs executable> A non-PATH location for the phantomjs executable');
log.log(' --no-run Do not execute the tests, just prep the server (for other testing)');
log.log(' --no-color Force no terminal colors');
log.log(' --debug Show internal grover debugging info');
log.log(' --console Show console.* messages from the test page');
log.log(' --combo <route>:<rootPath> Attach a combo server with these settings');
log.log(' Example: --combo /combo:./lib --combo /combo/foo:./foo');
log.log('');
log.log('Coverage Options');
log.log(' --coverage Generate a coverage report and print it to the screen (you must instrument your own files first)');
log.log(' --coverage-warn <Number> The percentage to highlight as low coverage: default is 80');
log.log(' --istanbul-report <Path> Generate an Instabul coverage report into this directory');
log.log(' --coverdir <Path> generate a full lcov coverage report here');
log.log(' -co --coverageFileName <path to export coverage file> The coverage data in lcov format.');
log.log(' -sp --sourceFilePrefix <path to sourcefile> The relative path to the original source file for use in the coverage results.');
util.exit();
break;
case "-v":
case "--version":
log.error(VERSION);
util.exit(1);
break;
case "-o":
case "--outfile":
options.outfile = args.shift();
break;
case "--tap":
options.outtype = 'TAP';
break;
case "--json":
options.outtype = 'JSON';
break;
case "--xml":
options.outtype = 'XML';
break;
case "--junit":
options.outtype = 'JUnitXML';
break;
default:
if (v.indexOf('-') === 0) {
log.error('Invalid option: ' + v);
util.exit(1);
break;
}
getPaths(v);
}
}
if (options.timeout <=0 ) {
options.timeout = null;
}
if (options['import']) {
if (!util.existsSync(options['import']) || util.existsSync(path.join(process.cwd(), options['import']))) {
options['import'] = path.join(process.cwd(), options['import']);
}
paths = require(options['import']);
if (paths && paths.length) {
options.paths = paths;
}
}
if ((options.prefix || options.suffix) && options.paths && options.paths.length) {
options.paths.forEach(function(p, i) {
newPath = p;
if (options.prefix) {
newPath = options.prefix + newPath;
}
if (options.suffix) {
newPath = newPath + options.suffix;
}
options.paths[i] = newPath;
});
}
return options;
};
exports.parse = parse;
|