Skip to content

Commit

Permalink
Added option to append timestamp to generated report filename.
Browse files Browse the repository at this point in the history
For issue #21 and issue #31 this allows parallel tests to run without overwriting generated reports.
  • Loading branch information
James Smith committed May 27, 2016
1 parent 28087a4 commit 142e4e9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 6 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ nconf.argv({
describe: 'Filename to use when saving the generated report.',
default: 'generatedReport.html'
},
u: {
alias: 'unique-filename',
describe: 'Appends a timestamp to the end of the generated report filename.',
default: false
},
p: {
alias: 'prepend-filename',
describe: 'Prepend filename to the package name in the report. Helps distinguish between multiple runs/diff browser/same test',
Expand Down Expand Up @@ -67,6 +72,7 @@ var opts = {
reportFilename: nconf.get('output'),
openBrowser: nconf.get('browser') === true,
prependFilename: nconf.get('prepend-filename') === true,
uniqueFilename: nconf.get('unique-filename') === true,
hideSuccess: typeof (nconf.get('compact')) !== 'undefined',
logLevel: nconf.get('log-level'),
debug: {
Expand Down
12 changes: 7 additions & 5 deletions lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ var fs = require('fs'),
module.exports = function(opts, testRun, callback) {

var save = typeof opts.saveFile === 'undefined' || opts.saveFile === true;
var filename = path.join(opts.reportsDirectory, opts.reportFilename);
var basename = path.basename(opts.reportFilename, '.html');
var filename = basename + ((opts.uniqueFilename) ? Date.now() : '') + '.html';
var outputPath = path.join(opts.reportsDirectory, filename);
var theme = path.join(__dirname, 'themes', opts.themeName, 'index.jade');

var html = null;
Expand All @@ -25,12 +27,12 @@ module.exports = function(opts, testRun, callback) {
// saving the file.
if (save) {
logger.log('Saving Report File');
fs.writeFile(filename, html, function(err) {
callback(err, filename, html, testRun);
fs.writeFile(outputPath, html, function(err) {
callback(err, outputPath, html, testRun);
});
} else {
callback(null, filename, html, testRun);
callback(null, outputPath, html, testRun);
}

return filename;
return outputPath;
};
1 change: 1 addition & 0 deletions lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = function(options) {
openBrowser: true,
hideSuccess: false,
reportFilename: 'report.html',
uniqueFilename: false,
themeName: 'default',
logLevel: 1,
debug: {
Expand Down

0 comments on commit 142e4e9

Please sign in to comment.