Add support for Outputting Autogenerated Test HTML

This commit introduces two flags, '-g' and '-o' to
the `run_from_console.js`.  Both flags do not run
the tests.  Instead, deal with the autogenerated
HTML.  The former outputs the paths to the autogenerated
HTML temp files, and then pauses the program until Ctrl-C
is pressed (or SIGINT is sent).  The latter outputs the
generated HTML for each files to STDIN with the names
of the tests to which they belong.
This commit is contained in:
Solly Ross 2013-12-04 15:39:20 -05:00
parent e0dc102e5b
commit 1e570156f9
1 changed files with 151 additions and 106 deletions

View File

@ -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,9 +66,54 @@ 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'));
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
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('');
}
if (program.generateHtml) {
process.stdin.resume(); // pause until C-c
process.on('SIGINT', function() {
process.stdin.pause(); // exit
});
}
if (!program.outputHtml && !program.generateHtml) {
var failure_count = 0;
var prov = require(path.resolve(__dirname, 'run_from_console.'+program.provider+'.js'));
cursor
.write("Running tests ")
.bold()
.write(program.tests.join(', '))
@ -77,10 +122,10 @@ cursor
.write(' using provider '+prov.name)
.reset()
.write("\n");
//console.log("Running tests %s using provider %s", program.tests.join(', '), prov.name);
//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) {
var provider = prov.provide_emitter(file_paths);
provider.on('test_ready', function(test_json) {
console.log('');
filename = program.tests[test_json.file_ind];
@ -182,15 +227,15 @@ provider.on('test_ready', function(test_json) {
console.log('all tests passed :-)');
cursor.reset();
}
});
});
/*provider.on('console', function(line) {
/*provider.on('console', function(line) {
//console.log(line);
});*/
});*/
/*gprom.finally(function(ph) {
/*gprom.finally(function(ph) {
ph.exit();
// exit with a status code that actually gives information
if (program.exitWithFailureCount) process.exit(failure_count);
});*/
});*/
}