mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Merge pull request #4034 from spalger/testing/fixDescribeOnly
[testing] simplify wrapping of mocha#ui and fix describe.only
This commit is contained in:
commit
dbbed300c0
1 changed files with 24 additions and 21 deletions
|
@ -9,30 +9,33 @@
|
|||
<script src="/src/kibana/bower_components/requirejs/require.js"></script>
|
||||
<script src="/src/kibana/require.config.js"></script>
|
||||
<script>(function () {
|
||||
var COVERAGE = !!(/coverage/i.test(window.location.search));
|
||||
var SAUCELABS = !!(/saucelabs/i.test(window.location.search));
|
||||
var DISABLE_RESIZE_CHECKER = true;
|
||||
/* globals mocha */
|
||||
|
||||
var COVERAGE = window.COVERAGE = !!(/coverage/i.test(window.location.search));
|
||||
var SAUCELABS = window.SAUCELABS = !!(/saucelabs/i.test(window.location.search));
|
||||
var DISABLE_RESIZE_CHECKER = window.DISABLE_RESIZE_CHECKER = true;
|
||||
|
||||
var mochaSuiteOn = mocha.suite.on;
|
||||
mocha.suite.on = function (eventName, fn) {
|
||||
if (eventName !== 'pre-require') {
|
||||
return mochaSuiteOn.call(this, eventName, fn);
|
||||
function wrap(obj, method, fn) {
|
||||
var orig = obj[method];
|
||||
return obj[method] = function methodProxy() {
|
||||
return fn.apply(this, [orig].concat([].slice.call(arguments)));
|
||||
};
|
||||
}
|
||||
|
||||
wrap(mocha, 'ui', function (orig, ui) {
|
||||
var ret = orig.call(this, ui);
|
||||
|
||||
var _desc = window.describe;
|
||||
window.describe = wrap(window, 'describe', unwindDescribeArrays);
|
||||
window.describe.only = wrap(_desc, 'only', unwindDescribeArrays);
|
||||
function unwindDescribeArrays(describe, name, body) {
|
||||
if (!body && name && name instanceof Array) {
|
||||
body = name[1]; name = name[0];
|
||||
}
|
||||
|
||||
return describe.call(this, name, body);
|
||||
}
|
||||
|
||||
return mochaSuiteOn.call(this, eventName, function (context, file, mocha) {
|
||||
fn.call(this, context, file, mocha);
|
||||
|
||||
var contextDescribe = context.describe;
|
||||
context.describe = function (name, body) {
|
||||
if (!body && name && name instanceof Array) {
|
||||
contextDescribe(name[0], name[1]);
|
||||
} else {
|
||||
contextDescribe(name, body);
|
||||
}
|
||||
};
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
mocha.setup({
|
||||
ui: 'bdd',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue