Skip to content

Commit 1997c4a

Browse files
committed
Run Karma tests against Microsoft Edge
* Increase the default timeouts to account for the relative slowness of setting up connections to remote browsers. * Change the URL into which Wombat JS is loaded for tests to be a valid URL. Under Microsoft Edge, the JS code in the page is not run if the URL fetch returns a 404. * Change assert.equal() implementation to avoid confusion due to Karma's reformatting of URLs in exception error messages.
1 parent e4e3de8 commit 1997c4a

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

karma-tests/dummy.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<head><meta charset="UTF-8"></head>
3+
<body>
4+
<!-- This is a dummy page used in
5+
tests of Wombat's live-rewriting
6+
functionality.
7+
!-->
8+
</body>
9+
</html>

karma-tests/karma.conf.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,10 @@ var sauceLaunchers = {
2828
version: '9.0',
2929
},
3030

31-
/* Edge is currently broken in
32-
pywb.
33-
34-
See: https://github.com/ikreymer/pywb/issues/148 (Edge)
35-
https://github.com/ikreymer/pywb/issues/147 (Safari)
36-
37-
3831
sl_edge: {
3932
base: 'SauceLabs',
4033
browserName: 'MicrosoftEdge',
4134
},
42-
*/
4335
};
4436

4537
var localLaunchers = {
@@ -73,6 +65,11 @@ module.exports = function(config) {
7365
included: false,
7466
served: true,
7567
},
68+
{
69+
pattern: 'karma-tests/dummy.html',
70+
included: false,
71+
served: true,
72+
},
7673
'karma-tests/*.spec.js',
7774
],
7875

@@ -90,12 +87,15 @@ module.exports = function(config) {
9087

9188
sauceLabs: sauceLabsConfig,
9289

93-
// use an extended timeout for capturing Sauce Labs
94-
// browsers and waiting for activity
95-
// in case the service is busy
90+
// Set extended timeouts to account for the slowness
91+
// in connecting to remote browsers (eg. when using
92+
// Sauce Labs)
93+
//
94+
// See https://oligofren.wordpress.com/2014/05/27/running-karma-tests-on-browserstack/
9695
captureTimeout: 3 * 60000,
97-
9896
browserNoActivityTimeout: 30 * 1000,
97+
browserDisconnectTimeout: 10 * 1000,
98+
browserDisconnectTolerance: 1,
9999

100100
customLaunchers: customLaunchers,
101101

karma-tests/wombat.spec.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
var WOMBAT_SRC = '../pywb/static/wombat.js';
21
var DEFAULT_TIMEOUT = 20000;
32

43
// creates a new document in an <iframe> and runs
@@ -12,7 +11,7 @@ var DEFAULT_TIMEOUT = 20000;
1211
function runWombatTest(testCase, done) {
1312
// create an <iframe>
1413
var testFrame = document.createElement('iframe');
15-
testFrame.src = '/dummy.html';
14+
testFrame.src = '/base/karma-tests/dummy.html';
1615
document.body.appendChild(testFrame);
1716

1817
testFrame.contentWindow.addEventListener('load', function () {
@@ -27,8 +26,20 @@ function runWombatTest(testCase, done) {
2726
done(new Error(ex));
2827
};
2928

30-
// expose chai assertions to the <iframe>
31-
window.assert = assert;
29+
// expose utility methods for assertion testing in tests.
30+
// (We used to expose chai asserts here but Karma's default
31+
// error reporter replaces URLs in exception messages with
32+
// the corresponding file paths, which is unhelpful for us
33+
// since assert.equal() will often be called with URLs in our tests)
34+
window.assert = {
35+
equal: function (a, b) {
36+
if (a !== b) {
37+
x.equal(a, b);
38+
console.error('Mismatch between', a, 'and', b);
39+
throw new Error('AssertionError');
40+
}
41+
}
42+
};
3243

3344
runFunctionInIFrame(function () {
3445
// re-assign the iframe's console object to the parent window's
@@ -136,7 +147,7 @@ describe('WombatJS', function () {
136147
testScript: function () {
137148
var link = document.getElementById('link');
138149
if (domTests.areDOMPropertiesConfigurable()) {
139-
assert.equal(link.href, 'http:///foobar.html');
150+
assert.equal(link.href, 'http:///base/karma-tests/foobar.html');
140151
}
141152
},
142153
}, done);
@@ -160,7 +171,7 @@ describe('WombatJS', function () {
160171
throw new Error('baseURI is not a string');
161172
}
162173
if (domTests.areDOMPropertiesConfigurable()) {
163-
assert.equal(baseURI, 'http:///dummy.html');
174+
assert.equal(baseURI, 'http:///base/karma-tests/dummy.html');
164175
}
165176
},
166177
}, done);

0 commit comments

Comments
 (0)