Skip to content

Commit

Permalink
feat(api): expose config.parseConfig on the public api
Browse files Browse the repository at this point in the history
  • Loading branch information
nicojs authored and dignifiedquire committed Nov 29, 2016
1 parent 8e2cfab commit 7d2c1ae
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/dev/04-public-api.md
Expand Up @@ -134,6 +134,20 @@ stopper.stop({port: 9876}, function(exitCode) {
})
```

## karma.config.parseConfig([configFilePath], [cliOptions])

This function will load given config file and returns a filled config object.
This can be useful if you want to integrate karma into another tool and want to load
the karma config while honoring the karma defaults. For example, the [stryker-karma-runner](https://github.com/stryker-mutator/stryker-karma-runner)
uses this to load your karma configuration and use that in the stryker configuration.

```javascript
const cfg = require('karma').config;
const path = require('path');
// Read karma.conf.js, but override port with 1337
const karmaConfig = cfg.parseConfig(path.resolve('./karma.conf.js'), { port: 1337 } );
```

## Callback function notes

- If there is an error, the error code will be provided as the second parameter to the error callback.
2 changes: 2 additions & 0 deletions lib/index.js
Expand Up @@ -5,6 +5,7 @@ var Server = require('./server')
var runner = require('./runner')
var stopper = require('./stopper')
var launcher = require('./launcher')
var cfg = require('./config')

// TODO: remove in 1.0
var oldServer = {
Expand All @@ -24,5 +25,6 @@ module.exports = {
runner: runner,
stopper: stopper,
launcher: launcher,
config: { parseConfig: cfg.parseConfig }, // lets start with only opening up the `parseConfig` api
server: oldServer
}
9 changes: 9 additions & 0 deletions test/unit/index.spec.js
@@ -0,0 +1,9 @@
var cfg = require('../../lib/config')

describe('index', () => {
var index = require('../../lib/index')

it('should expose the `config` object', () => {
expect(index.config.parseConfig).to.be.eq(cfg.parseConfig)
})
})

0 comments on commit 7d2c1ae

Please sign in to comment.