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 94
feat: support mocha opts #121
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is there an empty line here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dignifiedquire This line separte options which will pass to mocha in browser from options which use only on the server (like require) and not acceptable in browser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍