wix-incubator / mocha-env-reporter

10 stars 1 forks source link

Optionally get reporter name from environment #3

Closed Andreas-Hjortland closed 7 years ago

Andreas-Hjortland commented 7 years ago

Would it be possible to have an environment variable which explicitly told which reporter to use?

Something like

'use strict';

var reporter = process.env.mocha_reporter;
var builtInReporters = require('mocha').reporters;
if(!reporter) {
     // keep this for backwards compatibility
    module.exports = (process.env.BUILD_NUMBER || process.env.TEAMCITY_VERSION) ? require('mocha-teamcity-reporter') : builtInReporters.spec;
} else if(builtInReporters.hasOwnProperty(reporter)) {
    module.exports = builtInReporters[reporter];
} else {
    module.exports = require(reporter);
}

Then we could set the reporter using the environment variable mocha_reporter (e.g. for the dot reporter: mocha_reporter=dot mocha -r mocha-env-reporter) This would make this plugin useful in the case where we use another CI-solution like jenkins or bamboo.

amir-arad commented 7 years ago

sounds good. will do.

Andreas-Hjortland commented 7 years ago

If you want, I can just send a pull request of this change, because I have forked the repository and already made it.

amir-arad commented 7 years ago

@Andreas-Hjortland please do