-
Notifications
You must be signed in to change notification settings - Fork 18
/
run-browser.js
112 lines (94 loc) · 3.08 KB
/
run-browser.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
/* global global:true, __dirname, jasmineRequire */
/*jshint evil:true */
// reassigning causes eval to not use lexical scope.
var globalEval = eval,
global = globalEval('this');
/*jshint evil:false */
// Init
var jasmine = jasmineRequire.core(jasmineRequire);
var jasmineEnv = jasmine.getEnv();
// Export interface
var jasmineInterface = jasmineRequire.interface(jasmine, jasmineEnv);
global.jasmine = jasmine;
for (var property in jasmineInterface) {
if (jasmineInterface.hasOwnProperty(property)) {
global[property] = jasmineInterface[property];
}
}
//
// Init Reporter
//
function queryString(parameter) {
var i, key, value, equalSign;
var loc = location.search.substring(1, location.search.length);
var params = loc.split('&');
for (i=0; i<params.length;i++) {
equalSign = params[i].indexOf('=');
if (equalSign < 0) {
key = params[i];
if (key === parameter) {
value = true;
break;
}
}
else {
key = params[i].substring(0, equalSign);
if (key === parameter) {
value = decodeURIComponent(params[i].substring(equalSign+1));
break;
}
}
}
return value;
}
function insertParam(key, value) {
key = encodeURI(key);
value = encodeURI(value);
var param,
params = document.location.search.substr(1).split('&'),
i = params.length;
while(i--) {
param = params[i].split('=');
if (param[0] === key) {
param[1] = value;
params[i] = param.join('=');
break;
}
}
if (i < 0) {
params[params.length] = [key, value].join('=');
}
//this will reload the page, it's likely better to store this until finished
document.location.search = params.join('&');
}
// Default reporter
jasmineEnv.addReporter(jasmineInterface.jsApiReporter);
var catchingExceptions = queryString("catch");
jasmineEnv.catchExceptions(catchingExceptions === "false" ? false : true);
var queryString2 = new jasmineRequire.QueryString(jasmine)({
getWindowLocation: function() { return window.location; }
});
// Html reporter
jasmineRequire.html(jasmine);
var htmlReporter = new jasmine.HtmlReporter({
env: jasmineEnv,
queryString: queryString2,
onRaiseExceptionsClick: function() {
insertParam("catch", !jasmineEnv.catchingExceptions());
},
getContainer: function() { return document.body; },
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
timer: new jasmine.Timer()
});
htmlReporter.initialize();
jasmineEnv.addReporter(htmlReporter);
// Filter which specs will be run by matching the start of the full name against the `spec` query param.
var specFilter = new jasmine.HtmlSpecFilter({
filterString: function() {
return queryString("spec");
}
});
jasmineEnv.specFilter = function(spec) {
return specFilter.matches(spec.getFullName());
};