Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit eb2bdcc

Browse files
committed
Branch for testing gulp-web-component-tester integration.
1 parent 5251582 commit eb2bdcc

File tree

3 files changed

+232
-2
lines changed

3 files changed

+232
-2
lines changed

ci-browsers.json

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"local": [{
3+
"browserName": "chrome"
4+
}, {
5+
"browserName": "firefox"
6+
}, {
7+
"browserName": "safari"
8+
}],
9+
"remote": [{
10+
"browserName": "internet explorer",
11+
"version": "11",
12+
"platform": "Windows 8.1"
13+
}, {
14+
"browserName": "chrome",
15+
"platform": "Windows 8.1",
16+
"version": "36"
17+
}, {
18+
"browserName": "firefox",
19+
"platform": "Windows 8.1",
20+
"version": "31"
21+
}, {
22+
"browserName": "chrome",
23+
"platform": "OS X 10.9"
24+
}, {
25+
"browserName": "safari",
26+
"platform": "OS X 10.9",
27+
"version": "7"
28+
}, {
29+
"browserName": "iphone",
30+
"platform": "OS X 10.9",
31+
"version": "7.1"
32+
}, {
33+
"browserName": "android",
34+
"platform": "Linux",
35+
"version": "4.4",
36+
"deviceName": "Android"
37+
}]
38+
}

ci-support.js

+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
(function() {
2+
3+
var files;
4+
var stream;
5+
var runId;
6+
var browserId;
7+
8+
var thisFile = 'ci-support.js';
9+
var thisScript = document.querySelector('script[src$="' + thisFile + '"]');
10+
var base = thisScript.src.substring(0, thisScript.src.lastIndexOf('/')+1);
11+
12+
var tools = {
13+
'mocha-tdd': [
14+
base + 'mocha/mocha.css',
15+
base + 'mocha/mocha.js',
16+
base + 'mocha-htmltest.js',
17+
function() {
18+
var div = document.createElement('div');
19+
div.id = 'mocha';
20+
document.body.appendChild(div);
21+
mocha.setup({ui: 'tdd', slow: 1000, timeout: 5000, htmlbase: ''});
22+
}
23+
],
24+
'chai': [
25+
base + 'chai/chai.js'
26+
]
27+
};
28+
29+
function addFile() {
30+
var file = files.shift();
31+
if (Object.prototype.toString.call(file) == '[object Function]') {
32+
file();
33+
nextFile();
34+
}
35+
else if (file.slice(-3) == '.js') {
36+
var script = document.createElement('script');
37+
script.src = file;
38+
script.onload = nextFile;
39+
script.onerror = function() { console.error('Could not load ' + script.src); };
40+
document.head.appendChild(script);
41+
} else if (file.slice(-4) == '.css') {
42+
var sheet = document.createElement('link');
43+
sheet.rel = 'stylesheet';
44+
sheet.href = file;
45+
document.head.appendChild(sheet);
46+
nextFile();
47+
}
48+
}
49+
50+
function nextFile() {
51+
if (files.length) {
52+
addFile();
53+
} else {
54+
startMocha();
55+
}
56+
}
57+
58+
function getQueryVariable(variable) {
59+
var query = window.location.search.substring(1);
60+
var vars = query.split("&");
61+
for (var i=0;i<vars.length;i++) {
62+
var pair = vars[i].split("=");
63+
if (pair[0] == variable) {
64+
return pair[1];
65+
}
66+
}
67+
return(false);
68+
}
69+
70+
function runTests(setup) {
71+
stream = getQueryVariable('stream');
72+
runId = getQueryVariable('run');
73+
browserId = getQueryVariable('browser');
74+
files = [];
75+
76+
if (stream) {
77+
files.push('http://localhost:' + stream + '/socket.io/socket.io.js');
78+
}
79+
80+
if (typeof setup == 'string') {
81+
var xhr = new XMLHttpRequest();
82+
xhr.open('GET', setup);
83+
xhr.responseType = 'application/json';
84+
xhr.send();
85+
xhr.onreadystatechange = function() {
86+
if (xhr.readyState == 4) {
87+
setupTests(JSON.parse(xhr.response));
88+
}
89+
};
90+
} else {
91+
setupTests(setup);
92+
}
93+
}
94+
95+
function setupTests(setup) {
96+
if (setup.tools) {
97+
setup.tools.forEach(function(tool) {
98+
if (tools[tool]) {
99+
files = files.concat(tools[tool]);
100+
} else {
101+
console.error('Unknown tool: ' + tool);
102+
}
103+
});
104+
}
105+
if (setup.dependencies) {
106+
files = files.concat(setup.dependencies.map(function(d) {
107+
return '../' + d;
108+
}));
109+
}
110+
files = files.concat(setup.tests);
111+
nextFile();
112+
}
113+
114+
function startMocha() {
115+
var runner = mocha.run();
116+
117+
var socket;
118+
if (stream) {
119+
socket = io('http://localhost:' + stream);
120+
}
121+
var emitEvent = function(event, data) {
122+
if (socket) {
123+
console.log(event);
124+
socket.emit('mocha event', {event: event, browser: browserId, run: runId, data: data});
125+
}
126+
};
127+
128+
var failedTests = [];
129+
runner.on('end', function() {
130+
window.mochaResults = runner.stats;
131+
window.mochaResults.reports = failedTests;
132+
emitEvent('end', window.mochaResults);
133+
});
134+
135+
runner.on('fail', function(test, err) {
136+
var flattenTitles = function(test) {
137+
var titles = [];
138+
while (test.parent.title) {
139+
titles.push(test.parent.title);
140+
test = test.parent;
141+
}
142+
return titles.reverse();
143+
};
144+
var failure = {
145+
name: test.title,
146+
result: false,
147+
message: err.message,
148+
stack: err.stack,
149+
titles: flattenTitles(test)
150+
};
151+
failedTests.push(failure);
152+
emitEvent('fail', failure);
153+
});
154+
155+
// Other events
156+
if (socket) {
157+
['start', 'suite', 'suite end', 'test', 'test end', 'hook', 'hook end', 'pass'].forEach(function(event) {
158+
runner.on(event, function(data) {
159+
var cache = {};
160+
emitEvent(event, JSON.stringify(data, function(key, value) {
161+
if (!cache[value]) {
162+
cache[value] = true;
163+
return value;
164+
}
165+
}));
166+
});
167+
});
168+
}
169+
}
170+
171+
window.runTests = runTests;
172+
})();

htmltest.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ if (window.top === window) {
1212
window.onerror = null;
1313
if (!failed) {
1414
var d = document.createElement('pre');
15-
d.style.cssText = 'padding: 6px; background-color: lightgreen;';
15+
d.style.cssText = 'padding: 6px; background-color: lightgreen; position: absolute; bottom:0; right:10px;';
1616
d.textContent = 'Passed';
1717
document.body.appendChild(d);
1818
}
1919
};
2020
window.onerror = function(x) {
2121
failed = true;
2222
var d = document.createElement('pre');
23-
d.style.cssText = 'padding: 6px; background-color: #FFE0E0;';
23+
d.style.cssText = 'padding: 6px; background-color: #FFE0E0; position: absolute; bottom:0; right:10px;';
2424
d.textContent = 'FAILED: ' + x;
2525
document.body.appendChild(d);
2626
};
@@ -37,3 +37,23 @@ if (window.top === window) {
3737
};
3838
}
3939

40+
window.asyncSeries = function(series, callback) {
41+
series = series.slice();
42+
var next = function(err) {
43+
if (err) {
44+
callback(err);
45+
} else {
46+
var f = series.unshift();
47+
if (f) {
48+
try {
49+
f();
50+
} catch(e) {
51+
callback(e);
52+
}
53+
} else {
54+
callback();
55+
}
56+
}
57+
};
58+
next();
59+
};

0 commit comments

Comments
 (0)