Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
feat: Pass client configuration to `mocha.setup method.
Browse files Browse the repository at this point in the history
Now all configuration in `client.config.mocha` is passed to the
setup method of mocha. The default ui style of `'bdd'` is still
set if nothing else is supplied. Also the reporter will be always
overridden as this needs to be our custom one.

Fixes #13.
  • Loading branch information
dignifiedquire authored and vojtajina committed Nov 24, 2013
1 parent 1a0b871 commit 4df9ba6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ module.exports = function(config) {
};
```

If you want to pass configuration options directly to mocha you can
do this in the following way

```js
// karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['mocha'],

files: [
'*.js'
],

client: {
mocha: {
ui: 'tdd'
}
}
});
};
```

----

For more information on Karma see the [homepage].
Expand Down
32 changes: 32 additions & 0 deletions src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,35 @@ var createMochaStartFn = function(mocha) {
mocha.run();
};
};

// Default configuration
var mochaConfig = {
reporter: createMochaReporterConstructor(window.__karma__),
ui: 'bdd',
globals: ['__cov*']
};

// Pass options from client.mocha to mocha
var createConfigObject = function(karma) {
if (!karma.config || !karma.config.mocha) {
return mochaConfig;
}

// Copy all properties to mochaConfig
for (var key in karma.config.mocha) {

// except for reporter
if (key === 'reporter') {
return;
}

// and merge the globals if they exist.
if (key === 'globals' && karma.config.mocha[key].concat === 'function') {
return mochaConfig.globals.concat(karma.config.mocha[key]);
}

mochaConfig[key] = karma.config.mocha[key];
}
return mochaConfig;
};

3 changes: 1 addition & 2 deletions src/adapter.wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@


window.__karma__.start = createMochaStartFn(window.mocha);
window.mocha.setup({reporter: createMochaReporterConstructor(window.__karma__), ui: 'bdd',
globals: ['__cov*']});
window.mocha.setup(createConfigObject(window.__karma__));
})(window);

0 comments on commit 4df9ba6

Please sign in to comment.