forked from localForage/localForage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.js
75 lines (64 loc) · 1.9 KB
/
runner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* global requirejs:true */
// Run before window.onload to make sure the specs have access to describe()
// and other mocha methods. All feels very hacky though :-/
this.mocha.setup('bdd');
function runTests() {
var runner = this.mocha.run();
var failedTests = [];
runner.on('end', function() {
window.mochaResults = runner.stats;
window.mochaResults.reports = failedTests;
});
function flattenTitles(test) {
var titles = [];
while (test.parent.title) {
titles.push(test.parent.title);
test = test.parent;
}
return titles.reverse();
}
function logFailure(test, err) {
failedTests.push({
name: test.title,
result: false,
message: err.message,
stack: err.stack,
titles: flattenTitles(test)
});
}
runner.on('fail', logFailure);
}
if (!Array.prototype.forEach) {
Array.prototype.forEach = function(callback, thisArg) {
if (typeof callback !== 'function') {
throw new TypeError(callback + ' is not a function!');
}
var len = this.length;
for (var i = 0; i < len; i++) {
callback.call(thisArg, this[i], i, this);
}
};
}
var require = this.require;
if (require) {
requirejs.config({
paths: {
localforage: '/dist/localforage'
}
});
require(['localforage'], function(localforage) {
window.localforage = localforage;
require([
'/test/test.api.js',
'/test/test.config.js',
'/test/test.datatypes.js',
'/test/test.drivers.js',
'/test/test.iframes.js',
'/test/test.webworkers.js'
], runTests);
});
} else if (this.addEventListener) {
this.addEventListener('load', runTests);
} else if (this.attachEvent) {
this.attachEvent('onload', runTests);
}