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

Commit

Permalink
feat: allow requiring files via karma.conf.js
Browse files Browse the repository at this point in the history
Allow requiring files after mocha is initialised, via karma.conf.js

Closes #84
  • Loading branch information
Christian Schulze authored and christian-schulze committed Jun 26, 2016
1 parent 6dcb82a commit f00d6b3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@ module.exports = function(config) {

client: {
mocha: {
reporter: 'html', // change Karma's debug.html to the mocha web reporter
ui: 'tdd'
// change Karma's debug.html to the mocha web reporter
reporter: 'html',

// require specific files after Mocha is initialized
require: [require.resolve('bdd-lazy-var/bdd_lazy_var_global')],

// custom ui, defined in required file above
ui: 'bdd-lazy-var/global',
}
}
});
Expand Down
7 changes: 7 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ var createPattern = function (path) {
var initMocha = function (files, mochaConfig) {
var mochaPath = path.dirname(require.resolve('mocha'))
files.unshift(createPattern(path.join(__dirname, 'adapter.js')))

if (mochaConfig.require && mochaConfig.require.map) {
mochaConfig.require.map(function (requirePath) {
return files.unshift(createPattern(requirePath))
})
}

files.unshift(createPattern(path.join(mochaPath, 'mocha.js')))

if (mochaConfig && mochaConfig.reporter) {
Expand Down
4 changes: 2 additions & 2 deletions src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ var createConfigObject = function (karma) {

// Copy all properties to mochaConfig
for (var key in karma.config.mocha) {
// except for reporter
if (key === 'reporter') {
// except for reporter or require
if (['reporter', 'require'].indexOf(key) >= 0) {
continue
}

Expand Down
8 changes: 8 additions & 0 deletions test/adapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,14 @@ describe('adapter mocha', function () {
expect(createConfigObject(this.karma).reporter).not.to.eq('test')
})

it('should ignore propertie require from client config', function () {
this.karma.config.mocha = {
require: 'test'
}

expect(createConfigObject(this.karma).require).not.to.eq('test')
})

it('should merge the globals from client config if they exist', function () {
this.karma.config.mocha = {
globals: ['test']
Expand Down

0 comments on commit f00d6b3

Please sign in to comment.