mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
Merge pull request #8396 from ppisljar/fix/mochaDescribeOnly
fixing top_level_describe_filter to allow describe.only in unit tests
This commit is contained in:
commit
bde2591501
1 changed files with 29 additions and 22 deletions
|
@ -67,31 +67,38 @@ export function setupTopLevelDescribeFilter(test) {
|
||||||
let describeCallDepth = 0;
|
let describeCallDepth = 0;
|
||||||
const ignoredCalls = [];
|
const ignoredCalls = [];
|
||||||
|
|
||||||
|
const describeInterceptor = function (describeName, describeBody) {
|
||||||
|
const context = this;
|
||||||
|
|
||||||
|
const isTopLevelCall = describeCallDepth === 0;
|
||||||
|
const shouldIgnore = isTopLevelCall && Boolean(test(describeName)) === false;
|
||||||
|
if (shouldIgnore) return;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* we wrap the delegation to mocha in a try/finally block
|
||||||
|
* to ensure that our describeCallDepth counter stays up
|
||||||
|
* to date even if the call throws an error.
|
||||||
|
*
|
||||||
|
* note that try/finally won't actually catch the error, it
|
||||||
|
* will continue to propogate up the call stack
|
||||||
|
*/
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
describeCallDepth += 1;
|
||||||
|
result = originalDescribe.call(context, describeName, describeBody);
|
||||||
|
} finally {
|
||||||
|
describeCallDepth -= 1;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
// to allow describe.only calls. we dont need interceptor as it will call describe internally
|
||||||
|
describeInterceptor.only = originalDescribe.only;
|
||||||
|
|
||||||
// ensure that window.describe isn't messed with by other code
|
// ensure that window.describe isn't messed with by other code
|
||||||
Object.defineProperty(window, 'describe', {
|
Object.defineProperty(window, 'describe', {
|
||||||
configurable: false,
|
configurable: false,
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
value: function describeInterceptor(describeName, describeBody) {
|
value: describeInterceptor
|
||||||
const context = this;
|
|
||||||
|
|
||||||
const isTopLevelCall = describeCallDepth === 0;
|
|
||||||
const shouldIgnore = isTopLevelCall && Boolean(test(describeName)) === false;
|
|
||||||
if (shouldIgnore) return;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* we wrap the delegation to mocha in a try/finally block
|
|
||||||
* to ensure that our describeCallDepth counter stays up
|
|
||||||
* to date even if the call throws an error.
|
|
||||||
*
|
|
||||||
* note that try/finally won't actually catch the error, it
|
|
||||||
* will continue to propogate up the call stack
|
|
||||||
*/
|
|
||||||
try {
|
|
||||||
describeCallDepth += 1;
|
|
||||||
originalDescribe.call(context, describeName, describeBody);
|
|
||||||
} finally {
|
|
||||||
describeCallDepth -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue