UNPKG

3.58 kBJavaScriptView Raw
1#!/usr/bin/env node
2'use strict';
3
4const program = require('commander');
5let progOptions = program;
6const Config = require('./lib/config');
7const Api = require('./lib/api');
8let appMode = 'dev';
9
10program
11 .version(require(__dirname + '/package').version)
12 .usage('[options]')
13 .option('-f, --file [file]', 'config file - defaults to testem.json or testem.yml')
14 .option('-p, --port [num]', 'server port - defaults to 7357', Number)
15 .option('--host [hostname]', 'host name - defaults to localhost', String)
16 .option('-l, --launch [list]', 'list of launchers to launch(comma separated)')
17 .option('-s, --skip [list]', 'list of launchers to skip(comma separated)')
18 .option('-d, --debug [file]', 'output debug to debug log - defaults to testem.log')
19 .option('-t, --test_page [page]', 'the html page to drive the tests')
20 .option('-g, --growl', 'turn on growl / native notifications');
21
22program
23 .command('launchers')
24 .description('Print the list of available launchers (browsers & process launchers)')
25 .action(act(env => {
26 env.__proto__ = program;
27 progOptions = env;
28 appMode = 'launchers';
29 }));
30
31program
32 .command('ci')
33 .description('Continuous integration mode')
34 .option('-T, --timeout [sec]', 'timeout a browser after [sec] seconds', null)
35 .option('-P, --parallel [num]', 'number of browsers to run in parallel, defaults to 1', Number)
36 .option('-b, --bail_on_uncaught_error', 'Bail on any uncaught errors')
37 .option('-R, --reporter [reporter]', 'Test reporter to use [tap|dot|xunit|teamcity]')
38 .action(act(env => {
39 env.__proto__ = program;
40 progOptions = env;
41 appMode = 'ci';
42 }));
43
44program
45 .command('server')
46 .description('Run just the server')
47 .action(act(env => {
48 env.__proto__ = program;
49 progOptions = env;
50 appMode = 'server';
51 }));
52
53program.on('--help', () => {
54 console.log(' Keyboard Controls (in dev mode):\n');
55 console.log(' ENTER run the tests');
56 console.log(' q quit');
57 console.log(' LEFT ARROW move to the next browser tab on the left');
58 console.log(' RIGHT ARROW move to the next browser tab on the right');
59 console.log(' TAB switch between top and bottom panel (split mode only)');
60 console.log(' UP ARROW scroll up in the target text panel');
61 console.log(' DOWN ARROW scroll down in the target text panel');
62 console.log(' SPACE page down in the target text panel');
63 console.log(' b page up in the target text panel');
64 console.log(' d half a page down in the target text panel');
65 console.log(' u half a page up in the target text panel');
66 console.log();
67});
68
69main();
70function main() {
71 program.parse(process.argv);
72
73 let config = new Config(appMode, progOptions);
74 if (appMode === 'launchers') {
75 config.read(() => config.printLauncherInfo());
76 } else {
77 let api = new Api();
78 if (appMode === 'ci') {
79 api.startCI(progOptions);
80 } else if (appMode === 'dev') {
81 api.startDev(progOptions);
82 } else if (appMode === 'server') {
83 api.startServer(progOptions);
84 }
85 }
86}
87
88// this is to workaround the weird behavior in command where
89// if you provide additional command line arguments that aren't
90// options, it goes in as a string as the 1st arguments of the
91// "action" callback, we don't want this
92function act(fun) {
93 return function() {
94 let options = arguments[arguments.length - 1];
95 fun(options);
96 };
97}