mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
added auto-releasing sinon util
This commit is contained in:
parent
78580c1847
commit
8ae8f95033
5 changed files with 57 additions and 14 deletions
|
@ -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