Detecting Environment When Running Karma -
Detecting Environment When Running Karma -
i have 2 environments i'm running tests in (locally, , travic ci). , need create few tweaks in tests if i'm running them locally.
is possible using karma without having 2 separate configuration files?
you can programmatically phone call karma , pass configuration object, hear callback close server:
class="lang-js prettyprint-override">karma.server.start(config, function (exitcode){ if(exitcode){ console.err('error in somewhere!'); } });
the config object object contains properties , can utilize enrich skeleton configuration file have.
imagine have configuration file next in 'path/to/karma.conf.js':
class="lang-js prettyprint-override">// karma configuration module.exports = function(config) { config.set({ // base of operations path, used resolve files , exclude basepath: '../', // frameworks utilize frameworks: ['mocha'], files: [ ... ]. // test results reporter utilize // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage' // take before starting karma // web server port port: 9876, // enable / disable colors in output (reporters , logs) colors: true, // enable / disable watching file , executing tests whenever file changes autowatch: false, browsers: ['phantomjs'], // if browser not capture in given timeout [ms], kill capturetimeout: 60000, // continuous integration mode // if true, capture browsers, run tests , exit singlerun: true, plugins: [ 'karma-mocha', 'karma-phantomjs-launcher' ] }); };
now want tweak bit before starting karma:
class="lang-js prettyprint-override">function enrichconfig(path){ var moreconfig = { // want overwrite/choose reporter reporters: ['progress'], // set here path skeleton configuration file configfile: path }; homecoming moreconfig; } var config = enrichconfig('../path/to/karma.conf.js');
currently technique we're generating several configuration our environment.
i guess can configure travisci configuration file pass arguments wrapper in order activate particular property in enrichconfig
function.
if want pass parameters (e.g. configuration file path) script, in arguments array pick up.
assume script above saved in startkarma.js
file, alter code this:
var args = process.argv; // first 2 arguments 'node' , 'startkarma.js' var pathtoconfig = args[2]; var config = enrichconfig(pathtoconfig);
then:
class="lang-bash prettyprint-override">$ node startkarma.js ../path/to/karma.conf.js
karma-runner
Comments
Post a Comment