The client arguments (clientArgs) given to "karma run" have no effect when I'm using RequireJS -
i'm trying pass grep argument karma-mocha plugin pass mocha , run tests match grep. command line this:
./node_modules/.bin/karma run -- --grep='one' however, karma goes on tests, in same way if not use --grep. according karma run --help, after -- should client arguments. (it referred clientarg in , in discussions how run karma run.) tried small project without requirejs , worked. seems adding requirejs causes problem. here small setup reproduces issue:
karma.conf.js:
module.exports = function(config) { config.set({ basepath: '', frameworks: ['mocha', 'requirejs'], files: [ 'test-main.js', { pattern: 'test/**/*.js', included: false } ], exclude: [], preprocessors: {}, reporters: ['progress'], port: 9876, colors: true, loglevel: config.log_info, autowatch: false, browsers: ['chrome'], singlerun: false, concurrency: infinity }); }; test-main.js:
var alltestfiles = []; var test_regexp = /(spec|test)\.js$/i; object.keys(window.__karma__.files).foreach(function (file) { if (test_regexp.test(file)) { var normalizedtestmodule = file.replace(/^\/base\/|\.js$/g, ''); alltestfiles.push(normalizedtestmodule); } }); require.config({ baseurl: '/base', deps: alltestfiles, callback: window.__karma__.start }); what see here functionally equivalent stock test-main.js generated karma init. edited remove comments, normalize space, , add semi-colons.
the test/test.js file contains:
it("one", function () {}); it("two", function () {});
explanation
this problem how karma init generates test-main.js file used configure requirejs , kick off test. issue not specific mocha happen other runners accept parameters passed through clientargs.
the test-main.js generated karma init broken. you can see here when karma calls start itself, it calls own configuration:
this.loaded = function () { // has error -> cancel if (!haserror) { this.start(this.config) } [...] however, test-main.js created karma init calls start without argument, , why plugin not getting arguments should getting.
solution
modify test-main.js have callback in requirejs config:
callback: window.__karma__.start.bind(window.__karma__, window.__karma__.config) this cause start called in same way in code snippet shown earlier. if reason not bind or need more in callback, do:
callback: function () { // other stuff... window.__karma__.start.call(window.__karma__, window.__karma__.config); },
Comments
Post a Comment