Skip to content

Commit 3a1771b

Browse files
committed
Resolve conflict between qunit hooks for junit xml and browserscope
1 parent 8ca0eee commit 3a1771b

File tree

2 files changed

+45
-36
lines changed

2 files changed

+45
-36
lines changed

test/TestStacktrace.html

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,7 @@
2424
<link rel='stylesheet' href='lib/qunit.css' type='text/css' />
2525
<script type='text/javascript' src='lib/qunit.js'></script>
2626
<script type='text/javascript' src='lib/qunit-junit-outputter.js'></script>
27-
<script>
28-
var _bTestResults = {};
29-
30-
// Add URL option in QUnit to toggle publishing results to BrowserScope.org
31-
QUnit.config.urlConfig.push("publish");
32-
QUnit.config.testTimeout = 1000; // Timeout for async tests
33-
34-
// Build-up the test results beacon for BrowserScope.org
35-
QUnit.testDone = function(test) {
36-
// make sure all assertions passed successfully
37-
if (!test.failed && test.total === test.passed) {
38-
_bTestResults[test.name] = 1;
39-
} else {
40-
_bTestResults[test.name] = 0;
41-
}
42-
}
43-
44-
// If the user agreed to publish results to BrowserScope.org, go for it!
45-
QUnit.done = function() {
46-
if (QUnit.config.publish) {
47-
var testKey = 'agt1YS1wcm9maWxlcnINCxIEVGVzdBjr68MRDA';
48-
var newScript = document.createElement('script');
49-
var firstScript = document.getElementsByTagName('script')[0];
50-
51-
newScript.src = 'http://www.browserscope.org/user/beacon/' + testKey + "?callback=showResults";
52-
firstScript.parentNode.insertBefore(newScript, firstScript);
53-
}
54-
}
55-
56-
// Load the results widget from browserscope.org
57-
function showResults() {
58-
var script = document.createElement('script');
59-
script.src = "http://www.browserscope.org/user/tests/table/agt1YS1wcm9maWxlcnINCxIEVGVzdBjr68MRDA?o=js";
60-
document.body.appendChild(script);
61-
}
62-
</script>
27+
<script type='text/javascript' src='lib/qunit-browserscope.js'></script>
6328
<script type='text/javascript' src='../stacktrace.js'></script>
6429
<script type='text/javascript' src='CapturedExceptions.js'></script>
6530
<script type='text/javascript' src='TestStacktrace.js'></script>

test/lib/qunit-browserscope.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
var _bTestResults = {};
2+
3+
// Add URL option in QUnit to toggle publishing results to BrowserScope.org
4+
QUnit.config.urlConfig.push("publish");
5+
QUnit.config.testTimeout = 1000; // Timeout for async tests
6+
7+
// Prevent overwriting other hooks
8+
if (typeof QUnit.testDone === 'function') {
9+
QUnit.oldTestDone = QUnit.testDone;
10+
}
11+
if (typeof QUnit.done === 'function') {
12+
QUnit.oldDone = QUnit.done;
13+
}
14+
15+
// Build-up the test results beacon for BrowserScope.org
16+
QUnit.testDone = function(test) {
17+
QUnit.oldTestDone && QUnit.oldTestDone(test);
18+
// make sure all assertions passed successfully
19+
if (!test.failed && test.total === test.passed) {
20+
_bTestResults[test.name] = 1;
21+
} else {
22+
_bTestResults[test.name] = 0;
23+
}
24+
}
25+
26+
// If the user agreed to publish results to BrowserScope.org, go for it!
27+
QUnit.done = function(result) {
28+
QUnit.oldDone && QUnit.oldDone(result);
29+
if (QUnit.config.publish) {
30+
var testKey = 'agt1YS1wcm9maWxlcnINCxIEVGVzdBjr68MRDA';
31+
var newScript = document.createElement('script');
32+
var firstScript = document.getElementsByTagName('script')[0];
33+
34+
newScript.src = 'http://www.browserscope.org/user/beacon/' + testKey + "?callback=showResults";
35+
firstScript.parentNode.insertBefore(newScript, firstScript);
36+
}
37+
}
38+
39+
// Load the results widget from browserscope.org
40+
function showResults() {
41+
var script = document.createElement('script');
42+
script.src = "http://www.browserscope.org/user/tests/table/agt1YS1wcm9maWxlcnINCxIEVGVzdBjr68MRDA?o=js";
43+
document.body.appendChild(script);
44+
}

0 commit comments

Comments
 (0)