Skip to content

Commit

Permalink
Add the delegate 'modifyReportFilename' in order to allow to change t…
Browse files Browse the repository at this point in the history
…he report filename
  • Loading branch information
Miguel Ángel García committed Apr 1, 2016
1 parent 0c736b4 commit 4736abc
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/junit_reporter.js
Expand Up @@ -53,8 +53,8 @@

/**
* A delegate for letting the consumer
* modify the suite name when it is used inside the junit report and as a file
* name. This is useful when running a test suite against multiple capabilities
* modify the suite name when it is used inside the junit report.
* This is useful when running a test suite against multiple capabilities
* because the report can have unique names for each combination of suite/spec
* and capability/test environment.
*
Expand All @@ -63,6 +63,18 @@
* @param {object} suite
*/

/**
* A delegate for letting the consumer
* modify the report filename when it is used inside the junit report.
* This is useful when running a test suite against multiple capabilities
* because the report can have unique names for each combination of suite/spec
* and capability/test environment.
*
* @callback modifyReportFileName
* @param {string} suggestedName
* @param {object} suite
*/

/**
* Generates JUnit XML for the given spec run. There are various options
* to control where the results are written, and the default values are
Expand Down Expand Up @@ -93,8 +105,13 @@
* @param {string} [package] is the base package for all test suits that are
* handled by this report {default: none}
* @param {function} [modifySuiteName] a delegate for letting the consumer
* modify the suite name when it is used inside the junit report and as a file
* name. This is useful when running a test suite against multiple capabilities
* modify the suite name when it is used inside the junit report.
* This is useful when running a test suite against multiple capabilities
* because the report can have unique names for each combination of suite/spec
* and capability/test environment.
* @param {function} [modifyReportFileName] a delegate for letting the consumer
* modify the report filename.
* This is useful when running a test suite against multiple capabilities
* because the report can have unique names for each combination of suite/spec
* and capability/test environment.
* @param {function} [systemOut] a delegate for letting the consumer add content
Expand All @@ -121,12 +138,16 @@
if(options.modifySuiteName && typeof options.modifySuiteName !== 'function') {
throw new Error('option "modifySuiteName" must be a function');
}
if(options.modifyReportFileName && typeof options.modifyReportFileName !== 'function') {
throw new Error('option "modifyReportFileName" must be a function');
}
if(options.systemOut && typeof options.systemOut !== 'function') {
throw new Error('option "systemOut" must be a function');
}

var delegates = {};
delegates.modifySuiteName = options.modifySuiteName;
delegates.modifyReportFileName = options.modifyReportFileName;
delegates.systemOut = options.systemOut;

var suites = [],
Expand Down Expand Up @@ -299,6 +320,9 @@
fileName += chr;
}
}
if(delegates.modifyReportFileName) {
fileName = delegates.modifyReportFileName(fileName, suite);
}
return fileName;
} else {

Expand Down

0 comments on commit 4736abc

Please sign in to comment.