diff --git a/README.md b/README.md index 9c22208..f4a59f6 100644 --- a/README.md +++ b/README.md @@ -93,10 +93,10 @@ Filename for html report.
jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
savePath: './test/reports/',
- filePrefix: 'index'
+ fileNamePrefix: 'Prefix'
}));
-Default is htmlReport.html
+Default is nothing
### Consolidate and ConsolidateAll (optional)
@@ -130,3 +130,59 @@ This option, if false, will show only failures.
}));
Default is true
+
+### fileName (optional)
+
+This will be the name used for the html file generated thanks to this tool.
+
+jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
+ ....
+ fileName: 'MyReportName'
+}));
+
+Default is htmlReport
+
+### fileNameSeparator (optional)
+
+This will set the separator between filename elements, for example, prefix, sufix etc.
+
+jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
+ ....
+ fileNameSeparator: '_'
+}));
+
+Default is -
+
+### fileNamePrefix (optional)
+
+Prefix used before the name of the report
+
+jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
+ ....
+ fileNamePrefix: ''
+}));
+
+Default is empty
+
+### fileNameSuffix (optional)
+
+Prefix used after the name of the report
+
+jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
+ ....
+ fileNameSuffix: ''
+}));
+
+Default is empty
+
+### fileNameDateSuffix (optional)
+
+Datetime information to be added in the name of the report. This will be placed after the fileNameSuffix if it exists.
+The format is: YYYYMMDD HHMMSS,MILL -> 20161230 133323,728
+
+jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
+ ....
+ fileNameDateSuffix: true
+}));
+
+Default is false
\ No newline at end of file
diff --git a/index.js b/index.js
index e10df9f..12be361 100644
--- a/index.js
+++ b/index.js
@@ -7,7 +7,7 @@ var fs = require('fs'),
require('string.prototype.startswith');
-var UNDEFINED, exportObject = exports;
+var UNDEFINED, exportObject = exports, reportDate;
function sanitizeFilename(name){
name = name.replace(/\s+/gi, '-'); // Replace white space with dash
@@ -69,6 +69,19 @@ function rmdir(dir) {
}catch (e) { log("problem trying to remove a folder:" + dir); }
}
+function getReportDate(){
+ if (reportDate === undefined)
+ reportDate = new Date();
+ return reportDate.getFullYear() + '' +
+ (reportDate.getMonth() + 1) +
+ reportDate.getDate() + ' ' +
+ reportDate.getHours() + '' +
+ reportDate.getMinutes() + '' +
+ reportDate.getSeconds() + ',' +
+ reportDate.getMilliseconds();
+}
+
+
function Jasmine2HTMLReporter(options) {
var self = this;
@@ -85,7 +98,11 @@ function Jasmine2HTMLReporter(options) {
self.fixedScreenshotName = options.fixedScreenshotName === UNDEFINED ? false : options.fixedScreenshotName;
self.consolidate = options.consolidate === UNDEFINED ? true : options.consolidate;
self.consolidateAll = self.consolidate !== false && (options.consolidateAll === UNDEFINED ? true : options.consolidateAll);
- self.filePrefix = options.filePrefix || (self.consolidateAll ? 'htmlReport' : 'htmlReport-');
+ self.fileNameSeparator = options.fileNameSeparator === UNDEFINED ? '-' : options.fileNameSeparator;
+ self.fileNamePrefix = options.fileNamePrefix === UNDEFINED ? '' : options.fileNamePrefix;
+ self.fileNameSuffix = options.fileNameSuffix === UNDEFINED ? '' : options.fileNameSuffix;
+ self.fileNameDateSuffix = options.fileNameDateSuffix === UNDEFINED ? false : options.fileNameDateSuffix;
+ self.fileName = options.fileName === UNDEFINED ? 'htmlReport' : options.fileName;
self.cleanDestination = options.cleanDestination === UNDEFINED ? true : options.cleanDestination;
self.showPassed = options.showPassed === UNDEFINED ? true : options.showPassed;
@@ -110,6 +127,26 @@ function Jasmine2HTMLReporter(options) {
return __specs[spec.id];
}
+ function getReportFilename(specName){
+ var name = '';
+ console.log(self.fileNamePrefix);
+ if (self.fileNamePrefix)
+ name += self.fileNamePrefix + self.fileNameSeparator;
+
+ name += self.fileName;
+
+ if (specName !== undefined)
+ name += self.fileNameSeparator + specName;
+
+ if (self.fileNameSuffix)
+ name += self.fileNameSeparator + self.fileNameSuffix;
+
+ if (self.fileNameDateSuffix)
+ name += self.fileNameSeparator + getReportDate();
+
+ return name;
+ }
+
self.jasmineStarted = function(summary) {
totalSpecsDefined = summary && summary.totalSpecsDefined || NaN;
exportObject.startTime = new Date();
@@ -203,7 +240,7 @@ function Jasmine2HTMLReporter(options) {
}
// if we have anything to write here, write out the consolidated file
if (output) {
- wrapOutputAndWriteFile(self.filePrefix, output);
+ wrapOutputAndWriteFile(getReportFilename(), output);
}
//log("Specs skipped but not reported (entire suite skipped or targeted to specific specs)", totalSpecsDefined - totalSpecsExecuted + totalSpecsDisabled);
@@ -228,7 +265,7 @@ function Jasmine2HTMLReporter(options) {
/******** Helper functions with closure access for simplicity ********/
function generateFilename(suite) {
- return self.filePrefix + getFullyQualifiedSuiteName(suite, true) + '.html';
+ return getReportFilename(getFullyQualifiedSuiteName(suite, true));
}
function getFullyQualifiedSuiteName(suite, isFilename) {
@@ -365,9 +402,10 @@ function Jasmine2HTMLReporter(options) {
};
// To remove complexity and be more DRY about the silly preamble and