This repository has been archived by the owner on Dec 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #99
- Loading branch information
Showing
4 changed files
with
166 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,82 @@ | ||
var path = require('path') | ||
var extend = require('util')._extend | ||
var minimist = require('minimist') | ||
|
||
var createPattern = function (path) { | ||
return {pattern: path, included: true, served: true, watched: false} | ||
} | ||
|
||
var initMocha = function (files, mochaConfig) { | ||
var initMocha = function (files, config) { | ||
var mochaPath = path.dirname(require.resolve('mocha')) | ||
files.unshift(createPattern(path.join(__dirname, 'adapter.js'))) | ||
|
||
if (mochaConfig && mochaConfig.require && mochaConfig.require.map) { | ||
config = config || {} | ||
config.client = config.client || {} | ||
var mochaConfig = config.client.mocha = getMochaOpts(config.client.mocha || {}) | ||
|
||
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) { | ||
if (mochaConfig.reporter) { | ||
files.unshift(createPattern(path.join(mochaPath, 'mocha.css'))) | ||
} | ||
} | ||
|
||
initMocha.$inject = ['config.files', 'config.client.mocha'] | ||
initMocha.$inject = ['config.files', 'config'] | ||
|
||
module.exports = { | ||
'framework:mocha': ['factory', initMocha] | ||
} | ||
|
||
function getMochaOpts (mochaConfig) { | ||
var optsPath = typeof mochaConfig.opts === 'string' ? mochaConfig.opts : 'test/mocha.opts' | ||
|
||
if (!mochaConfig.opts) { | ||
return mochaConfig | ||
} | ||
|
||
delete mochaConfig.opts | ||
|
||
var fs = require('fs') | ||
if (!fs.existsSync(optsPath)) { | ||
return mochaConfig | ||
} | ||
|
||
return extend(normalizeOpts(minimist(fs.readFileSync(optsPath, 'utf8') | ||
.replace(/\\\s/g, '%20') | ||
.split(/\s/) | ||
.filter(Boolean) | ||
.map(function (value) { | ||
return value.replace(/%20/g, ' ') | ||
}))), mochaConfig) | ||
|
||
function normalizeOpts (opts) { | ||
opts = [ | ||
'require', | ||
|
||
'ui', | ||
'reporter', | ||
'globals', | ||
'grep', | ||
'timeout', | ||
'slow', | ||
'bail', | ||
'ignoreLeaks' | ||
].reduce(function (result, optName) { | ||
if (opts.hasOwnProperty(optName)) { | ||
result[optName] = opts[optName] | ||
} | ||
|
||
return result | ||
}, {}) | ||
|
||
opts.require = [].concat(opts.require || []) | ||
|
||
return opts | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,9 @@ | |
"mocha" | ||
], | ||
"author": "Vojta Jina <[email protected]>", | ||
"dependencies": {}, | ||
"dependencies": { | ||
"minimist": "1.2.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.4.1", | ||
"eslint": "^2.0.0", | ||
|
@@ -42,6 +44,7 @@ | |
"karma-sinon": "^1.0.3", | ||
"load-grunt-tasks": "^3.2.0", | ||
"mocha": "^3.0.0", | ||
"mock-fs": "^3.12.1", | ||
"shared-karma-files": "git://github.com/karma-runner/shared-karma-files.git#82ae8d02", | ||
"sinon": "^1.17.2" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters