Skip to content

Commit

Permalink
load libraries before unit tests... duh
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer Alger committed Oct 31, 2014
1 parent fdd2609 commit 2ddafa7
Showing 1 changed file with 48 additions and 40 deletions.
88 changes: 48 additions & 40 deletions test/unit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@
require([
'kibana',
'sinon/sinon',
'angular',
'angular'
], loadSpecs);
}

function loadSpecs(kibana, sinon) {
require([
'specs/apps/discover/hit_sort_fn',
'specs/apps/discover/directives/table',
'specs/apps/discover/directives/discover_field',
Expand Down Expand Up @@ -153,49 +158,52 @@
'specs/visualize/_create_raw_data',
'specs/visualize/_array_to_linked_list',
'specs/visualize/_collect_branch'
], function (kibana, sinon) {
kibana.load(function () {
var xhr = sinon.useFakeXMLHttpRequest();

window.mochaRunner = mocha.run().on('end', function () {
window.mochaResults = this.stats;
window.mochaResults.details = getFailedTests(this);
xhr.restore();
});

function getFailedTests(runner) {
var fails = [];
var suiteStack = [];

(function recurse(suite) {
suiteStack.push(suite);

(suite.tests || [])
.filter(function (test) {
return test.state !== 'passed' && test.state !== 'pending';
})
.forEach(function (test) {
fails.push({
title: suiteStack.concat(test).reduce(function (title, suite) {
if (suite.title) {
return (title ? title + ' ' : '') + suite.title;
} else {
return title;
}
}, ''),
err: test.err ? (test.err.stack || test.err.message) : 'unknown error'
});
});
], function () {
bootstrap(kibana, sinon);
});
}

(suite.suites || []).forEach(recurse);
function bootstrap(kibana, sinon) {
kibana.load(function () {
var xhr = sinon.useFakeXMLHttpRequest();

suiteStack.pop();
}(runner.suite));
window.mochaRunner = mocha.run().on('end', function () {
window.mochaResults = this.stats;
window.mochaResults.details = getFailedTests(this);
xhr.restore();
});

return fails;
}
function getFailedTests(runner) {
var fails = [];
var suiteStack = [];

(function recurse(suite) {
suiteStack.push(suite);

(suite.tests || [])
.filter(function (test) {
return test.state !== 'passed' && test.state !== 'pending';
})
.forEach(function (test) {
fails.push({
title: suiteStack.concat(test).reduce(function (title, suite) {
if (suite.title) {
return (title ? title + ' ' : '') + suite.title;
} else {
return title;
}
}, ''),
err: test.err ? (test.err.stack || test.err.message) : 'unknown error'
});
});

});
(suite.suites || []).forEach(recurse);

suiteStack.pop();
}(runner.suite));

return fails;
}
});
}

Expand Down

0 comments on commit 2ddafa7

Please sign in to comment.