mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Merge pull request #5891 from spalger/implement/mochaSetup
formalize mocha setup
This commit is contained in:
commit
c54b9ca6b7
4 changed files with 46 additions and 2 deletions
|
@ -56,8 +56,8 @@
|
|||
"elasticsearchWithPlugins": "grunt esvm:withPlugins:keepalive",
|
||||
"lint": "grunt eslint:source",
|
||||
"lintroller": "grunt eslint:fixSource",
|
||||
"mocha": "mocha --compilers js:babel/register",
|
||||
"mocha:debug": "mocha --debug-brk --compilers js:babel/register"
|
||||
"mocha": "mocha",
|
||||
"mocha:debug": "mocha --debug-brk"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require('../../test/mocha_setup');
|
||||
|
||||
module.exports = {
|
||||
options: {
|
||||
timeout: 10000,
|
||||
|
|
1
test/mocha.opts
Normal file
1
test/mocha.opts
Normal file
|
@ -0,0 +1 @@
|
|||
--require test/mocha_setup.js
|
41
test/mocha_setup.js
Normal file
41
test/mocha_setup.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
var sinon = require('sinon');
|
||||
var autoRelease = require('auto-release-sinon');
|
||||
|
||||
require('babel/register')(require('../src/optimize/babelOptions').node);
|
||||
|
||||
// hook into the global afterEach variable to allow autoReleaseSinon to register
|
||||
// an afterEach handler before mocha has exposed itself to the test files.
|
||||
//
|
||||
// This works by telling autoReleaseSinon to use a fake "afterEach" function.
|
||||
// Rather than actually record an afterEach handler the function tracks all of
|
||||
// the calls it received and queues them up in queuedAfterEachArgs.
|
||||
//
|
||||
// The global "afterEach" variable is also tracked, and once it is assigned by mocha
|
||||
// the variable global is reconfigured to point directly to the new value (from mocha)
|
||||
// and all of the queued invocations are executed.
|
||||
var queuedAfterEachArgs = [];
|
||||
Object.defineProperty(global, 'afterEach', {
|
||||
configurable: true,
|
||||
get() { return undefined; },
|
||||
set(afterEach) {
|
||||
Object.defineProperty(global, 'afterEach', {
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: afterEach
|
||||
});
|
||||
|
||||
queuedAfterEachArgs.forEach(function (args) {
|
||||
afterEach.apply(null, args);
|
||||
});
|
||||
|
||||
return global.afterEach;
|
||||
}
|
||||
});
|
||||
|
||||
autoRelease.setupAutoRelease(sinon, function () {
|
||||
if (!global.afterEach) {
|
||||
queuedAfterEachArgs.push(Array.prototype.slice.call(arguments));
|
||||
} else {
|
||||
global.afterEach.apply(this, arguments);
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue