UNPKG

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