1 |
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | var scriptsToLoad = [
|
6 | '../lib/localstorage-memory.js'
|
7 | ];
|
8 |
|
9 |
|
10 | function asyncLoadScript(url, callback) {
|
11 |
|
12 |
|
13 | var script = document.createElement('script');
|
14 | var firstScript = document.getElementsByTagName('script')[0];
|
15 |
|
16 | script.async = true;
|
17 | script.src = url;
|
18 |
|
19 |
|
20 | if ('function' === typeof(callback)) {
|
21 | script.onload = function () {
|
22 | callback();
|
23 |
|
24 |
|
25 |
|
26 | script.onload = script.onreadystatechange = undefined;
|
27 | };
|
28 | script.onreadystatechange = function () {
|
29 | if ('loaded' === script.readyState || 'complete' === script.readyState) {
|
30 | script.onload();
|
31 | }
|
32 | };
|
33 | }
|
34 |
|
35 |
|
36 |
|
37 | firstScript.parentNode.insertBefore(script, firstScript);
|
38 | }
|
39 |
|
40 | function startTests() {
|
41 |
|
42 | function onReady() {
|
43 | var runner = mocha.run();
|
44 | window.results = {
|
45 | lastPassed: '',
|
46 | passed: 0,
|
47 | failed: 0,
|
48 | failures: []
|
49 | };
|
50 |
|
51 | runner.on('pass', function (e) {
|
52 | window.results.lastPassed = e.title;
|
53 | window.results.passed++;
|
54 | });
|
55 |
|
56 | runner.on('fail', function (e) {
|
57 | window.results.failed++;
|
58 | window.results.failures.push({
|
59 | title: e.title,
|
60 | message: e.err.message,
|
61 | stack: e.err.stack
|
62 | });
|
63 | });
|
64 |
|
65 | runner.on('end', function () {
|
66 | window.results.completed = true;
|
67 | window.results.passed++;
|
68 | });
|
69 | }
|
70 |
|
71 | function loadNext() {
|
72 | if (scriptsToLoad.length) {
|
73 | var script = scriptsToLoad.shift();
|
74 | asyncLoadScript(script, loadNext);
|
75 | } else {
|
76 | onReady();
|
77 | }
|
78 | }
|
79 |
|
80 | loadNext();
|
81 | }
|
82 |
|
83 | startTests();
|