forked from pouchdb/pouchdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webrunner.js
142 lines (123 loc) · 4.42 KB
/
webrunner.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*globals $:false, console: false */
"use strict";
// use query parameter testFiles if present,
// eg: test.html?testFiles=test.basics.js
var testFiles = window.location.search.match(/[?&]testFiles=([^&]+)/);
testFiles = testFiles && testFiles[1].split(',') || [];
var started = new Date();
if (!testFiles.length) {
// If you want to run performance tests, uncomment these tests
// and comment out the testFiles below
//testFiles = [
// 'perf.attachments.js'
//];
// Temporarily disable auth replication
// 'test.auth_replication.js',
testFiles = ['test.basics.js', 'test.changes.js',
'test.bulk_docs.js', 'test.all_docs.js', 'test.conflicts.js',
'test.merge_rev_tree.js', 'test.revs_diff.js',
'test.replication.js', 'test.views.js',
'test.design_docs.js', 'test.issue221.js', 'test.http.js'];
// attachments dont run well on the ci server yet.
// if there is a hash, it is because the git rev is put on the url as a hash
// take that as a sign not to run the attachment tests
if (!window.location.hash || window.location.hash.length === 0) {
testFiles.push('test.attachments.js');
}
}
testFiles.unshift('test.utils.js');
var sourceFiles = {
'dev': ['../src/deps/uuid.js',
'../src/pouch.js', '../src/pouch.adapter.js', '../src/pouch.merge.js', '../src/pouch.replicate.js',
'../src/pouch.collate.js', '../src/pouch.utils.js',
'../src/adapters/pouch.http.js', '../src/adapters/pouch.idb.js',
'../src/adapters/pouch.websql.js',
'../src/plugins/pouchdb.mapreduce.js',
'../src/plugins/pouchdb.spatial.js'],
'release': ['../dist/pouchdb-nightly.js'],
'release-min': ['../dist/pouchdb-nightly.min.js']
};
// Thanks to http://engineeredweb.com/blog/simple-async-javascript-loader/
function asyncLoadScript(url, callback) {
// Create a new script and setup the basics.
var script = document.createElement("script"),
firstScript = document.getElementsByTagName('script')[0];
script.async = true;
script.src = url;
// Handle the case where an optional callback was passed in.
if ( "function" === typeof(callback) ) {
script.onload = function() {
callback();
// Clear it out to avoid getting called more than once or any memory leaks.
script.onload = script.onreadystatechange = undefined;
};
script.onreadystatechange = function() {
if ( "loaded" === script.readyState || "complete" === script.readyState ) {
script.onload();
}
};
}
// Attach the script tag to the page (before the first script) so the
//magic can happen.
firstScript.parentNode.insertBefore(script, firstScript);
}
function startQUnit() {
QUnit.config.reorder = false;
QUnit.begin = function() {
console.log('running!!!');
};
}
function asyncParForEach(array, fn, callback) {
if (array.length === 0) {
callback(); // done immediately
return;
}
var toLoad = array.shift();
fn(toLoad, function() {
asyncParForEach(array, fn, callback);
});
}
var source = window.location.search.match(/[?&]test=([^&]+)/);
source = source && source[1] || 'dev';
QUnit.config.testTimeout = 30000;
/**** Test Result Support ***************/
function submitResults() {
var notice = document.createElement('p');
var button = document.getElementById('submit-results');
button.textContent = 'uploading...';
button.setAttribute('disabled', 'disabled');
$.ajax({
type: 'POST',
url: 'http://localhost:2020/_replicate',
data: JSON.stringify({
source: 'test_suite_db1',
target: 'http://reupholster.iriscouch.com/pouch_tests'
}),
success: function() {
document.body.classList.add('completed');
button.style.display = 'none';
notice.appendChild(document.createTextNode('Submission Complete'));
document.body.appendChild(notice);
},
error: function() {
document.body.classList.add('completed');
},
headers: {
Accept: 'application/json'
},
dataType: 'json',
contentType: 'application/json'
});
}
document.getElementById('submit-results').addEventListener('click', submitResults);
QUnit.jUnitReport = function(report) {
report.started = started;
report.completed = new Date();
report.passed = (report.results.failed === 0);
window.testReport = report;
};
asyncParForEach(sourceFiles[source], asyncLoadScript, function() {
asyncParForEach(testFiles, asyncLoadScript, function() {
startQUnit();
});
});