diff --git a/lib/cli/index.js b/lib/cli/index.js index e145a9305..c75651a27 100644 --- a/lib/cli/index.js +++ b/lib/cli/index.js @@ -31,6 +31,7 @@ exports.run = () => { program.command('test [paths...]') .allowUnknownOption(true) .option('-r, --reporter ', 'test reporter. Available reporters are: flat, vflat, html.', collect) + .option('--html-reporter-path ', 'Relative path where html reporters will be stored', collect) .option('-s, --set ', 'set to run', collect) .description('run tests') .action((paths, options) => runGemini('test', paths, options).done()); @@ -96,9 +97,17 @@ function runGemini(method, paths, options) { return gemini; }) .then((gemini) => { + function parseReporterOptions(options) { + return options.reporter.map(function(name) { + return { + name, + path: options[`${name}ReporterPath`] + }; + }); + } return gemini[method](paths, { sets: options.set, - reporters: options.reporter || ['flat'], + reporters: parseReporterOptions(options) || [{name: 'flat'}], grep: program.grep, browsers: program.browser, diff: options.diff, diff --git a/lib/gemini.js b/lib/gemini.js index ee2fb4e85..526f156b9 100644 --- a/lib/gemini.js +++ b/lib/gemini.js @@ -184,17 +184,23 @@ module.exports = class Gemini extends PassthroughEmitter { function applyReporter(runner, reporter) { if (typeof reporter === 'string') { + reporter = {name: reporter}; + } + if (typeof reporter === 'object') { + const reporterPath = reporter.path; try { - reporter = require('./reporters/' + reporter); + reporter = require('./reporters/' + reporter.name); } catch (e) { if (e.code === 'MODULE_NOT_FOUND') { - throw new GeminiError('No such reporter: ' + reporter); + throw new GeminiError('No such reporter: ' + reporter.name); } throw e; } + + return reporter(runner, reporterPath); } if (typeof reporter !== 'function') { - throw new TypeError('Reporter must be a string or a function'); + throw new TypeError('Reporter must be a string, an object or a function'); } reporter(runner); diff --git a/lib/reporters/html/index.js b/lib/reporters/html/index.js index b5b28abdd..83727d060 100644 --- a/lib/reporters/html/index.js +++ b/lib/reporters/html/index.js @@ -63,8 +63,8 @@ function logError(e) { console.error(e.stack); } -function logPathToHtmlReport() { - const reportPath = `file://${path.resolve('gemini-report/index.html')}`; +function logPathToHtmlReport(reporterPath) { + const reportPath = `file://${path.resolve((reporterPath || lib.REPORT_DIR) + '/index.html')}`; logger.log(`Your HTML report is here: ${chalk.yellow(reportPath)}`); } @@ -122,11 +122,11 @@ function prepareImages(runner) { }); } -module.exports = function htmlReporter(runner) { +module.exports = function htmlReporter(runner, reportPath) { const generateReportPromise = Promise.all([prepareViewData(runner), prepareImages(runner)]) .spread(view.createHtml) - .then(view.save) - .then(logPathToHtmlReport) + .then((html) => view.save(html, reportPath)) + .then(logPathToHtmlReport(reportPath)) .catch(logError); runner.on(Events.END_RUNNER, () => generateReportPromise.thenReturn()); diff --git a/lib/reporters/html/view.js b/lib/reporters/html/view.js index 80aef462e..8e4881c26 100644 --- a/lib/reporters/html/view.js +++ b/lib/reporters/html/view.js @@ -91,8 +91,8 @@ module.exports = { * @param {String} html * returns {Promise} */ - save: function(html) { - return fs.mkdirsAsync(REPORT_DIR) + save: function(html, reportPath) { + return fs.mkdirsAsync(reportPath || REPORT_DIR) .then(() => Promise.all([ fs.writeFileAsync(makeOutFilePath('index.html'), html, 'utf8'), copyToReportDir('report.min.js'),