Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.

Commit b25409e

Browse files
HeeLSergii Paryzhskyi
authored andcommitted
feat(html-reporter): add ability to specify output path for each report
1 parent a1b4f34 commit b25409e

4 files changed

Lines changed: 26 additions & 11 deletions

File tree

lib/cli/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ exports.run = () => {
3131
program.command('test [paths...]')
3232
.allowUnknownOption(true)
3333
.option('-r, --reporter <reporter>', 'test reporter. Available reporters are: flat, vflat, html.', collect)
34+
.option('--html-reporter-path <path>', 'Relative path where html reporters will be stored', collect)
3435
.option('-s, --set <set>', 'set to run', collect)
3536
.description('run tests')
3637
.action((paths, options) => runGemini('test', paths, options).done());
@@ -96,9 +97,17 @@ function runGemini(method, paths, options) {
9697
return gemini;
9798
})
9899
.then((gemini) => {
100+
function parseReporterOptions(options) {
101+
return options.reporter.map(function(name) {
102+
return {
103+
name,
104+
path: options[`${name}ReporterPath`]
105+
};
106+
});
107+
}
99108
return gemini[method](paths, {
100109
sets: options.set,
101-
reporters: options.reporter || ['flat'],
110+
reporters: parseReporterOptions(options) || [{name: 'flat'}],
102111
grep: program.grep,
103112
browsers: program.browser,
104113
diff: options.diff,

lib/gemini.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,23 @@ module.exports = class Gemini extends PassthroughEmitter {
184184

185185
function applyReporter(runner, reporter) {
186186
if (typeof reporter === 'string') {
187+
reporter = {name: reporter};
188+
}
189+
if (typeof reporter === 'object') {
190+
const reporterPath = reporter.path;
187191
try {
188-
reporter = require('./reporters/' + reporter);
192+
reporter = require('./reporters/' + reporter.name);
189193
} catch (e) {
190194
if (e.code === 'MODULE_NOT_FOUND') {
191-
throw new GeminiError('No such reporter: ' + reporter);
195+
throw new GeminiError('No such reporter: ' + reporter.name);
192196
}
193197
throw e;
194198
}
199+
200+
return reporter(runner, reporterPath);
195201
}
196202
if (typeof reporter !== 'function') {
197-
throw new TypeError('Reporter must be a string or a function');
203+
throw new TypeError('Reporter must be a string, an object or a function');
198204
}
199205

200206
reporter(runner);

lib/reporters/html/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ function logError(e) {
6363
console.error(e.stack);
6464
}
6565

66-
function logPathToHtmlReport() {
67-
const reportPath = `file://${path.resolve('gemini-report/index.html')}`;
66+
function logPathToHtmlReport(reporterPath) {
67+
const reportPath = `file://${path.resolve((reporterPath || lib.REPORT_DIR) + '/index.html')}`;
6868

6969
logger.log(`Your HTML report is here: ${chalk.yellow(reportPath)}`);
7070
}
@@ -122,11 +122,11 @@ function prepareImages(runner) {
122122
});
123123
}
124124

125-
module.exports = function htmlReporter(runner) {
125+
module.exports = function htmlReporter(runner, reportPath) {
126126
const generateReportPromise = Promise.all([prepareViewData(runner), prepareImages(runner)])
127127
.spread(view.createHtml)
128-
.then(view.save)
129-
.then(logPathToHtmlReport)
128+
.then((html) => view.save(html, reportPath))
129+
.then(logPathToHtmlReport(reportPath))
130130
.catch(logError);
131131

132132
runner.on(Events.END_RUNNER, () => generateReportPromise.thenReturn());

lib/reporters/html/view.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ module.exports = {
9191
* @param {String} html
9292
* returns {Promise}
9393
*/
94-
save: function(html) {
95-
return fs.mkdirsAsync(REPORT_DIR)
94+
save: function(html, reportPath) {
95+
return fs.mkdirsAsync(reportPath || REPORT_DIR)
9696
.then(() => Promise.all([
9797
fs.writeFileAsync(makeOutFilePath('index.html'), html, 'utf8'),
9898
copyToReportDir('report.min.js'),

0 commit comments

Comments
 (0)