tracked down XHR requests that the tests were cuasing, included some nextTick into the callback handling, tests should be passing properly now

This commit is contained in:
Spencer Alger 2014-03-06 17:35:08 -07:00
parent aa18485f16
commit 67dc27511a
5 changed files with 25 additions and 59 deletions

3
.gitignore vendored
View file

@ -1,2 +1,3 @@
.DS_Store
node_modules
node_modules
test/unit/index.html

View file

@ -50,11 +50,11 @@ define(function (require) {
if (err) {
// If we are unable to get the fields from cache, get them from mapping
self.getFieldsFromMapping(dataSource, function (err, fields) {
if (err) return courier._error(err);
if (err) return callback(err);
// And then cache them
cacheFieldsToElasticsearch(config, dataSource._state.index, fields, function (err, response) {
if (err) return courier._error(new CacheWriteFailure());
if (err) return callback(new CacheWriteFailure());
});
cacheFieldsToObject(dataSource, fields);

View file

@ -1,44 +0,0 @@
<!DOCTYPE html><html><head><title>Kibana4 Tests</title><link rel="stylesheet" href="/node_modules/mocha/mocha.css"></head><body><div id="mocha"></div><script src="/node_modules/expect.js/expect.js"></script><script src="/node_modules/mocha/mocha.js"></script><script src="/src/bower_components/requirejs/require.js"></script><script src="/src/kibana/require.config.js"></script><script type="text/javascript">window.COVERAGE = !!(/coverage/i.test(window.location.search));
mocha.setup('bdd');
require.config({
baseUrl: '/src/kibana',
paths: {
testUtils: '../../test/utils',
sinon: '../../test/utils/sinon'
},
shim: {
'sinon/sinon': {
deps: [
'sinon/sinon-timers-1.8.2'
],
exports: 'sinon'
}
},
// mark all requested files with instrument query param
urlArgs: COVERAGE ? 'instrument=true' : void 0
});
function setupCoverage(done) {
document.title = document.title.replace('Tests', 'Coverage');
require([
'testUtils/istanbul_reporter/reporter'
], function (IstanbulReporter) {
mocha.reporter(IstanbulReporter);
done();
});
}
function runTests() {
require(["../../test/unit/specs/apps/dashboard/index","../../test/unit/specs/calculate_indices","../../test/unit/specs/courier","../../test/unit/specs/data_source","../../test/unit/specs/mapper"], function () {
window.mochaRunner = mocha.run().on('end', function () {
window.mochaResults = this.stats;
});
});
}
if (COVERAGE) {
setupCoverage(runTests);
} else {
runTests();
}</script></body></html>

View file

@ -42,9 +42,15 @@ html
}
function runTests() {
require(!{JSON.stringify(tests)}, function () {
require(['sinon/sinon'].concat(!{JSON.stringify(tests)}), function (sinon) {
var xhr = sinon.useFakeXMLHttpRequest();
xhr.onCreate = function () {
throw new Error('Tests should not be sending XHR requests');
};
window.mochaRunner = mocha.run().on('end', function () {
window.mochaResults = this.stats;
xhr.restore();
});
});
}

View file

@ -18,7 +18,7 @@ define(function (require) {
});
describe('Mapper', function () {
var server, source, mapper;
var source, mapper;
beforeEach(function () {
source = courier.createSource('search')
@ -46,7 +46,7 @@ define(function (require) {
});
sinon.stub(client, 'delete', function (params, callback) {
callback(undefined, true);
nextTick(callback, undefined, true);
});
});
@ -116,6 +116,10 @@ define(function (require) {
callback({error: 'Stubbed cache get failure'});
});
sinon.stub(client, 'index', function (params, callback) {
nextTick(callback, null, {});
});
sinon.spy(mapper, 'getFieldsFromMapping');
mapper.getFields(source, function (err, mapping) {
@ -149,16 +153,15 @@ define(function (require) {
source = courier.createSource('search')
.index('invalid')
.size(5);
try {
mapper.getFields(source, function (err, mapping) {
// Should not be called
expect('the callback').to.be('not executed');
done();
});
} catch (e) {
expect(true).to.be(true);
sinon.stub(client, 'index', function (params, callback) {
nextTick(callback, undefined, {});
});
mapper.getFields(source, function (err, mapping) {
expect(err).to.be.ok();
done();
}
});
});
it('has a clearCache that calls client.delete', function (done) {