|
@@ -14,6 +14,8 @@ program
|
|
|
.option('-c, --color', 'Explicitly enable color (default is to use color when not outputting to a pipe)')
|
|
|
.option('-i, --auto-inject <includefiles>', 'Treat the test list as a set of mocha JS files, and automatically generate HTML files with which to test test. \'includefiles\' should be a comma-separated list of paths to javascript files to include in each of the generated HTML files', make_list, null)
|
|
|
.option('-p, --provider <name>', 'Use the given provider (defaults to "casper"). Currently, may be "casper" or "zombie"', 'casper')
|
|
|
+ .option('-g, --generate-html', 'Instead of running the tests, just return the path to the generated HTML file, then wait for user interaction to exit (should be used with -i)')
|
|
|
+ .option('-o, --output-html', 'Instead of running the tests, just output the generated HTML source to STDOUT (should be used with -i)')
|
|
|
.parse(process.argv);
|
|
|
|
|
|
var file_paths = [];
|
|
@@ -57,8 +59,6 @@ else {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-var failure_count = 0;
|
|
|
-
|
|
|
var use_ansi = false;
|
|
|
if (program.color) use_ansi = true;
|
|
|
else if (program.disableColor) use_ansi = false;
|
|
@@ -66,131 +66,176 @@ else if (process.stdout.isTTY) use_ansi = true;
|
|
|
|
|
|
var cursor = ansi(process.stdout, { enabled: use_ansi });
|
|
|
|
|
|
-var prov = require(path.resolve(__dirname, 'run_from_console.'+program.provider+'.js'));
|
|
|
-
|
|
|
-cursor
|
|
|
- .write("Running tests ")
|
|
|
- .bold()
|
|
|
- .write(program.tests.join(', '))
|
|
|
- .reset()
|
|
|
- .grey()
|
|
|
- .write(' using provider '+prov.name)
|
|
|
- .reset()
|
|
|
- .write("\n");
|
|
|
-//console.log("Running tests %s using provider %s", program.tests.join(', '), prov.name);
|
|
|
-
|
|
|
-var provider = prov.provide_emitter(file_paths);
|
|
|
-provider.on('test_ready', function(test_json) {
|
|
|
+if (program.outputHtml) {
|
|
|
+ var fs = require('fs');
|
|
|
+ file_paths.forEach(function(path, path_ind) {
|
|
|
+ fs.readFile(path, function(err, data) {
|
|
|
+ if (err) {
|
|
|
+ console.warn(error.stack);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ cursor
|
|
|
+ .bold()
|
|
|
+ .write(program.tests[path_ind])
|
|
|
+ .reset()
|
|
|
+ .write("\n")
|
|
|
+ .write(Array(program.tests[path_ind].length+1).join('='))
|
|
|
+ .write("\n\n")
|
|
|
+ .write(data)
|
|
|
+ .write("\n");
|
|
|
+ });
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+if (program.generateHtml) {
|
|
|
+ file_paths.forEach(function(path, path_ind) {
|
|
|
+ cursor
|
|
|
+ .bold()
|
|
|
+ .write(program.tests[path_ind])
|
|
|
+ .write(": ")
|
|
|
+ .reset()
|
|
|
+ .write(path)
|
|
|
+ .write("\n");
|
|
|
+ });
|
|
|
console.log('');
|
|
|
+}
|
|
|
|
|
|
- filename = program.tests[test_json.file_ind];
|
|
|
+if (program.generateHtml) {
|
|
|
+ process.stdin.resume(); // pause until C-c
|
|
|
+ process.on('SIGINT', function() {
|
|
|
+ process.stdin.pause(); // exit
|
|
|
+ });
|
|
|
+}
|
|
|
|
|
|
- cursor.bold();
|
|
|
- console.log('Results for %s:', filename);
|
|
|
- console.log(Array('Results for :'.length+filename.length+1).join('='));
|
|
|
- cursor.reset();
|
|
|
+if (!program.outputHtml && !program.generateHtml) {
|
|
|
+ var failure_count = 0;
|
|
|
|
|
|
- console.log('');
|
|
|
+ var prov = require(path.resolve(__dirname, 'run_from_console.'+program.provider+'.js'));
|
|
|
|
|
|
- cursor.write(''+test_json.num_tests+' tests run, ')
|
|
|
- cursor
|
|
|
- .green()
|
|
|
- .write(''+test_json.num_passes+' passed');
|
|
|
- if (test_json.num_slow > 0) {
|
|
|
- cursor
|
|
|
- .reset()
|
|
|
- .write(' (');
|
|
|
- cursor
|
|
|
- .yellow()
|
|
|
- .write(''+test_json.num_slow+' slow')
|
|
|
- .reset()
|
|
|
- .write(')');
|
|
|
- }
|
|
|
cursor
|
|
|
+ .write("Running tests ")
|
|
|
+ .bold()
|
|
|
+ .write(program.tests.join(', '))
|
|
|
.reset()
|
|
|
- .write(', ');
|
|
|
- cursor
|
|
|
- .red()
|
|
|
- .write(''+test_json.num_fails+' failed');
|
|
|
- cursor
|
|
|
+ .grey()
|
|
|
+ .write(' using provider '+prov.name)
|
|
|
.reset()
|
|
|
- .write(' -- duration: '+test_json.duration+"\n");
|
|
|
+ .write("\n");
|
|
|
+ //console.log("Running tests %s using provider %s", program.tests.join(', '), prov.name);
|
|
|
|
|
|
- console.log('');
|
|
|
+ var provider = prov.provide_emitter(file_paths);
|
|
|
+ provider.on('test_ready', function(test_json) {
|
|
|
+ console.log('');
|
|
|
|
|
|
- if (test_json.num_fails > 0 || program.printAll) {
|
|
|
- var traverse_tree = function(indentation, node) {
|
|
|
- if (node.type == 'suite') {
|
|
|
- if (!node.has_subfailures && !program.printAll) return;
|
|
|
+ filename = program.tests[test_json.file_ind];
|
|
|
|
|
|
- if (indentation == 0) {
|
|
|
- cursor.bold();
|
|
|
- console.log(node.name);
|
|
|
- console.log(Array(node.name.length+1).join('-'));
|
|
|
- cursor.reset();
|
|
|
- }
|
|
|
- else {
|
|
|
- cursor
|
|
|
- .write(Array(indentation+3).join('#'))
|
|
|
- .bold()
|
|
|
- .write(' '+node.name+' ')
|
|
|
- .reset()
|
|
|
- .write(Array(indentation+3).join('#'))
|
|
|
- .write("\n");
|
|
|
- }
|
|
|
+ cursor.bold();
|
|
|
+ console.log('Results for %s:', filename);
|
|
|
+ console.log(Array('Results for :'.length+filename.length+1).join('='));
|
|
|
+ cursor.reset();
|
|
|
|
|
|
- console.log('');
|
|
|
+ console.log('');
|
|
|
+
|
|
|
+ cursor.write(''+test_json.num_tests+' tests run, ')
|
|
|
+ cursor
|
|
|
+ .green()
|
|
|
+ .write(''+test_json.num_passes+' passed');
|
|
|
+ if (test_json.num_slow > 0) {
|
|
|
+ cursor
|
|
|
+ .reset()
|
|
|
+ .write(' (');
|
|
|
+ cursor
|
|
|
+ .yellow()
|
|
|
+ .write(''+test_json.num_slow+' slow')
|
|
|
+ .reset()
|
|
|
+ .write(')');
|
|
|
+ }
|
|
|
+ cursor
|
|
|
+ .reset()
|
|
|
+ .write(', ');
|
|
|
+ cursor
|
|
|
+ .red()
|
|
|
+ .write(''+test_json.num_fails+' failed');
|
|
|
+ cursor
|
|
|
+ .reset()
|
|
|
+ .write(' -- duration: '+test_json.duration+"\n");
|
|
|
+
|
|
|
+ console.log('');
|
|
|
+
|
|
|
+ if (test_json.num_fails > 0 || program.printAll) {
|
|
|
+ var traverse_tree = function(indentation, node) {
|
|
|
+ if (node.type == 'suite') {
|
|
|
+ if (!node.has_subfailures && !program.printAll) return;
|
|
|
+
|
|
|
+ if (indentation == 0) {
|
|
|
+ cursor.bold();
|
|
|
+ console.log(node.name);
|
|
|
+ console.log(Array(node.name.length+1).join('-'));
|
|
|
+ cursor.reset();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ cursor
|
|
|
+ .write(Array(indentation+3).join('#'))
|
|
|
+ .bold()
|
|
|
+ .write(' '+node.name+' ')
|
|
|
+ .reset()
|
|
|
+ .write(Array(indentation+3).join('#'))
|
|
|
+ .write("\n");
|
|
|
+ }
|
|
|
|
|
|
- for (var i = 0; i < node.children.length; i++) {
|
|
|
- traverse_tree(indentation+1, node.children[i]);
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- if (!node.pass) {
|
|
|
- cursor.magenta();
|
|
|
- console.log('- failed: '+node.text+test_json.replay);
|
|
|
- cursor.red();
|
|
|
- console.log(' '+node.error.split("\n")[0]); // the split is to avoid a weird thing where in PhantomJS, we get a stack trace too
|
|
|
- cursor.reset();
|
|
|
console.log('');
|
|
|
+
|
|
|
+ for (var i = 0; i < node.children.length; i++) {
|
|
|
+ traverse_tree(indentation+1, node.children[i]);
|
|
|
+ }
|
|
|
}
|
|
|
- else if (program.printAll) {
|
|
|
- if (node.slow) cursor.yellow();
|
|
|
- else cursor.green();
|
|
|
- cursor
|
|
|
- .write('- pass: '+node.text)
|
|
|
- .grey()
|
|
|
- .write(' ('+node.duration+') ');
|
|
|
- /*if (node.slow) cursor.yellow();
|
|
|
- else cursor.green();*/
|
|
|
- cursor
|
|
|
- //.write(test_json.replay)
|
|
|
- .reset()
|
|
|
- .write("\n");
|
|
|
- console.log('');
|
|
|
+ else {
|
|
|
+ if (!node.pass) {
|
|
|
+ cursor.magenta();
|
|
|
+ console.log('- failed: '+node.text+test_json.replay);
|
|
|
+ cursor.red();
|
|
|
+ console.log(' '+node.error.split("\n")[0]); // the split is to avoid a weird thing where in PhantomJS, we get a stack trace too
|
|
|
+ cursor.reset();
|
|
|
+ console.log('');
|
|
|
+ }
|
|
|
+ else if (program.printAll) {
|
|
|
+ if (node.slow) cursor.yellow();
|
|
|
+ else cursor.green();
|
|
|
+ cursor
|
|
|
+ .write('- pass: '+node.text)
|
|
|
+ .grey()
|
|
|
+ .write(' ('+node.duration+') ');
|
|
|
+ /*if (node.slow) cursor.yellow();
|
|
|
+ else cursor.green();*/
|
|
|
+ cursor
|
|
|
+ //.write(test_json.replay)
|
|
|
+ .reset()
|
|
|
+ .write("\n");
|
|
|
+ console.log('');
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- for (var i = 0; i < test_json.suites.length; i++) {
|
|
|
- traverse_tree(0, test_json.suites[i]);
|
|
|
+ for (var i = 0; i < test_json.suites.length; i++) {
|
|
|
+ traverse_tree(0, test_json.suites[i]);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (test_json.num_fails == 0) {
|
|
|
- cursor.fg.green();
|
|
|
- console.log('all tests passed :-)');
|
|
|
- cursor.reset();
|
|
|
- }
|
|
|
-});
|
|
|
-
|
|
|
-/*provider.on('console', function(line) {
|
|
|
- //console.log(line);
|
|
|
-});*/
|
|
|
+ if (test_json.num_fails == 0) {
|
|
|
+ cursor.fg.green();
|
|
|
+ console.log('all tests passed :-)');
|
|
|
+ cursor.reset();
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
-/*gprom.finally(function(ph) {
|
|
|
- ph.exit();
|
|
|
- // exit with a status code that actually gives information
|
|
|
- if (program.exitWithFailureCount) process.exit(failure_count);
|
|
|
-});*/
|
|
|
+ /*provider.on('console', function(line) {
|
|
|
+ //console.log(line);
|
|
|
+ });*/
|
|
|
|
|
|
+ /*gprom.finally(function(ph) {
|
|
|
+ ph.exit();
|
|
|
+ // exit with a status code that actually gives information
|
|
|
+ if (program.exitWithFailureCount) process.exit(failure_count);
|
|
|
+ });*/
|
|
|
+}
|