added auto-releasing sinon util

This commit is contained in:
Spencer Alger 2014-03-06 14:39:37 -07:00
parent 78580c1847
commit 8ae8f95033
5 changed files with 57 additions and 14 deletions

View file

@ -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();
});

View file

@ -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();
});

View file

@ -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');

View file

@ -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);

View 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;
});