mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
4118fceef7
7 changed files with 109 additions and 46 deletions
|
@ -4,6 +4,7 @@ define(function (require) {
|
|||
var $ = require('jquery');
|
||||
var configFile = require('../config');
|
||||
var nextTick = require('utils/next_tick');
|
||||
var modules = require('modules');
|
||||
|
||||
/**
|
||||
* Setup the kibana application, ensuring that the kibanaIndex exists,
|
||||
|
@ -26,9 +27,7 @@ define(function (require) {
|
|||
// create the setup module, it should require the same things
|
||||
// that kibana currently requires, which should only include the
|
||||
// loaded modules
|
||||
var setup = angular.module('setup');
|
||||
var unlink = require('modules').link(setup);
|
||||
|
||||
var setup = modules.get('setup', ['elasticsearch']);
|
||||
var appEl = document.createElement('div');
|
||||
var kibanaIndexExists;
|
||||
|
||||
|
@ -48,8 +47,8 @@ define(function (require) {
|
|||
// ready to go, remove the appEl, close services and boot be done
|
||||
angular.element(appEl).remove();
|
||||
|
||||
// stop adding modules to this one
|
||||
unlink();
|
||||
// linked modules should no longer depend on this module
|
||||
setup.close();
|
||||
|
||||
console.log('booting kibana');
|
||||
return done(err);
|
||||
|
|
|
@ -4,38 +4,59 @@ define(function (require) {
|
|||
var _ = require('lodash');
|
||||
var links = [];
|
||||
|
||||
return {
|
||||
link: function (module) {
|
||||
// as modules are defined they will be set as requirements for this app
|
||||
links.push(module);
|
||||
function link(module) {
|
||||
// as modules are defined they will be set as requirements for this app
|
||||
links.push(module);
|
||||
|
||||
// merge in the existing modules
|
||||
module.requires = _.union(module.requires, _.keys(existingModules));
|
||||
// merge in the existing modules
|
||||
module.requires = _.union(module.requires, _.keys(existingModules));
|
||||
}
|
||||
|
||||
// function to call that will unlink the module
|
||||
return function unlink() {
|
||||
var i = links.indexOf(module);
|
||||
if (i > -1) links.splice(i, 1);
|
||||
};
|
||||
},
|
||||
get: function (moduleName, requires) {
|
||||
var module = existingModules[moduleName];
|
||||
function get(moduleName, requires) {
|
||||
var module = existingModules[moduleName];
|
||||
|
||||
if (module === void 0) {
|
||||
// create the module
|
||||
module = existingModules[moduleName] = angular.module(moduleName, []);
|
||||
// ensure that it is required by linked modules
|
||||
_.each(links, function (app) {
|
||||
if (!~app.requires.indexOf(moduleName)) app.requires.push(moduleName);
|
||||
});
|
||||
}
|
||||
if (module === void 0) {
|
||||
// create the module
|
||||
module = existingModules[moduleName] = angular.module(moduleName, []);
|
||||
|
||||
if (requires) {
|
||||
// update requires list with possibly new requirements
|
||||
module.requires = _.union(module.requires, requires);
|
||||
}
|
||||
module.close = _.partial(close, moduleName);
|
||||
|
||||
return module;
|
||||
// ensure that it is required by linked modules
|
||||
_.each(links, function (app) {
|
||||
if (!~app.requires.indexOf(moduleName)) app.requires.push(moduleName);
|
||||
});
|
||||
}
|
||||
|
||||
if (requires) {
|
||||
// update requires list with possibly new requirements
|
||||
module.requires = _.union(module.requires, requires);
|
||||
}
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
function close(moduleName) {
|
||||
var module = existingModules[moduleName];
|
||||
|
||||
// already closed
|
||||
if (!module) return;
|
||||
|
||||
// if the module is currently linked, unlink it
|
||||
var i = links.indexOf(module);
|
||||
if (i > -1) links.splice(i, 1);
|
||||
|
||||
// remove from linked modules list of required modules
|
||||
_.each(links, function (app) {
|
||||
_.pull(app.requires, moduleName);
|
||||
});
|
||||
|
||||
// remove module from existingModules
|
||||
delete existingModules[moduleName];
|
||||
}
|
||||
|
||||
return {
|
||||
link: link,
|
||||
get: get,
|
||||
close: close
|
||||
};
|
||||
});
|
|
@ -4,8 +4,8 @@ mocha.setup('bdd');
|
|||
require.config({
|
||||
baseUrl: '/src/kibana',
|
||||
paths: {
|
||||
sinon: '../../test/utils/sinon',
|
||||
istanbul_reporter: '../../test/utils/istanbul_reporter'
|
||||
testUtils: '../../test/utils',
|
||||
sinon: '../../test/utils/sinon'
|
||||
},
|
||||
shim: {
|
||||
'sinon/sinon': {
|
||||
|
@ -21,7 +21,9 @@ require.config({
|
|||
|
||||
function setupCoverage(done) {
|
||||
document.title = document.title.replace('Tests', 'Coverage');
|
||||
require(['istanbul_reporter/reporter'], function (IstanbulReporter) {
|
||||
require([
|
||||
'testUtils/istanbul_reporter/reporter'
|
||||
], function (IstanbulReporter) {
|
||||
mocha.reporter(IstanbulReporter);
|
||||
done();
|
||||
});
|
||||
|
|
|
@ -16,8 +16,8 @@ html
|
|||
require.config({
|
||||
baseUrl: '/src/kibana',
|
||||
paths: {
|
||||
sinon: '../../test/utils/sinon',
|
||||
istanbul_reporter: '../../test/utils/istanbul_reporter'
|
||||
testUtils: '../../test/utils',
|
||||
sinon: '../../test/utils/sinon'
|
||||
},
|
||||
shim: {
|
||||
'sinon/sinon': {
|
||||
|
@ -33,7 +33,9 @@ html
|
|||
|
||||
function setupCoverage(done) {
|
||||
document.title = document.title.replace('Tests', 'Coverage');
|
||||
require(['istanbul_reporter/reporter'], function (IstanbulReporter) {
|
||||
require([
|
||||
'testUtils/istanbul_reporter/reporter'
|
||||
], function (IstanbulReporter) {
|
||||
mocha.reporter(IstanbulReporter);
|
||||
done();
|
||||
});
|
||||
|
|
|
@ -2,7 +2,6 @@ define(function (require) {
|
|||
var mocks = require('angular-mocks');
|
||||
var _ = require('lodash');
|
||||
var $ = require('jquery');
|
||||
var sinon = require('sinon/sinon');
|
||||
|
||||
// Load the kibana app dependencies.
|
||||
require('angular-route');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
define(function (require) {
|
||||
var elasticsearch = require('bower_components/elasticsearch/elasticsearch');
|
||||
var _ = require('lodash');
|
||||
var sinon = require('sinon/sinon');
|
||||
var sinon = require('testUtils/auto_release_sinon');
|
||||
var Courier = require('courier/courier');
|
||||
var DataSource = require('courier/data_source/data_source');
|
||||
var Mapper = require('courier/mapper');
|
||||
|
@ -46,12 +46,6 @@ define(function (require) {
|
|||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.indices.getFieldMapping.restore();
|
||||
client.getSource.restore();
|
||||
client.delete.restore();
|
||||
});
|
||||
|
||||
it('provides a constructor for the Mapper class', function (done) {
|
||||
var mapper = new Mapper(courier);
|
||||
expect(mapper).to.be.a(Mapper);
|
||||
|
|
46
test/utils/auto_release_sinon.js
Normal file
46
test/utils/auto_release_sinon.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
define(function (require) {
|
||||
|
||||
var sinon = require('sinon/sinon');
|
||||
var _ = require('lodash');
|
||||
|
||||
var toRestore = [];
|
||||
var toWrap = {
|
||||
stub: null,
|
||||
spy: null,
|
||||
useFakeTimers: function (clock) {
|
||||
// timeouts are indexed by their id in an array,
|
||||
// the holes make the .length property "wrong"
|
||||
clock.timeoutCount = function () {
|
||||
return clock.timeoutList().length;
|
||||
};
|
||||
|
||||
clock.timeoutList = function () {
|
||||
return clock.timeouts ? clock.timeouts.filter(Boolean) : [];
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
_.forOwn(toWrap, function (modify, method) {
|
||||
var orig = sinon[method];
|
||||
sinon[method] = function () {
|
||||
var obj = orig.apply(sinon, arguments);
|
||||
|
||||
// after each test this list is cleared
|
||||
toRestore.push(obj);
|
||||
|
||||
return obj;
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
if (!toRestore.length) return;
|
||||
|
||||
_.each(toRestore, function (obj) {
|
||||
obj.restore();
|
||||
});
|
||||
|
||||
toRestore = [];
|
||||
});
|
||||
|
||||
return sinon;
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue