Skip to content

Commit 88fd07a

Browse files
committed
Save test results to file
1 parent 1ec0d24 commit 88fd07a

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

test/css/test.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,8 @@ h1, h2 {
8989
margin-top: 40px;
9090
visibility: hidden;
9191
}
92+
93+
#saveContainer {
94+
margin-top: 75px;
95+
visibility: hidden;
96+
}

test/js/testLauncher.js

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
status = null,
4343
realtimeReadout = null,
4444
currentTest = null,
45-
fieldContainer = null;
45+
fieldContainer = null,
46+
saveButton = null;
4647

4748
var inputIgnoredEvent = false,
4849
validationFailedEvent = false,
@@ -56,8 +57,13 @@
5657
realtimeReadout = $( "#realtimeReadout" );
5758
currentTest = $( "#currentTest" );
5859
fieldContainer = $( "#fieldContainer" );
60+
saveButton = $( "#saveButton" );
5961
} );
6062

63+
function saveReport( xml ) {
64+
var uriContent = "data:application/octet-stream," + encodeURIComponent( report );
65+
}
66+
6167
function resetEventFlags() {
6268
log( "resetting event flags" );
6369

@@ -144,6 +150,20 @@
144150
}
145151
}
146152

153+
function download( filename, text ) {
154+
var a = $( "<a/>", {
155+
"href" : "data:text/plain;charset=utf-8," + encodeURIComponent( text ),
156+
"download" : filename
157+
} );
158+
159+
// Odd... jQuery.click() doesn't trigger the link, even if it's appended to the page first.
160+
// Oh well, regular ol' JS to the rescue.
161+
162+
var event = document.createEvent( "MouseEvents" );
163+
event.initEvent( "click", true, true );
164+
a[0].dispatchEvent( event );
165+
}
166+
147167
if( validateTestCases(testCases) ) {
148168
QUnit.config.hidepassed = true;
149169

@@ -175,11 +195,28 @@
175195
}
176196

177197
realtimeReadout.remove();
178-
document.getElementById( "done" ).style.visibility = "visible";
198+
$( "#done" ).css( "visibility", "visible" );
179199

180-
if( typeof console !== "undefined" ) {
181-
console.log( report.xml ); // TODO: Export this out of the browser
182-
}
200+
saveButton.on( "click", function() {
201+
function zeroPad( datePart ) {
202+
return datePart < 10 ? "0" + datePart : datePart;
203+
}
204+
205+
var d = new Date();
206+
207+
var year = d.getFullYear(),
208+
month = zeroPad( d.getMonth() + 1 ),
209+
day = zeroPad( d.getDate() ),
210+
hour = zeroPad( d.getHours() ),
211+
min = zeroPad( d.getMinutes() ),
212+
sec = zeroPad( d.getSeconds() );
213+
214+
var timestamp = year + "-" + month + "-" + day + "_" + hour + "-" + min + "-" + sec;
215+
216+
download( "RestrictedTextField-TestResult-" + timestamp + ".xml", report.xml );
217+
} );
218+
219+
$( "#saveContainer" ).css( "visibility", "visible" );
183220
} );
184221

185222
QUnit.cases( testCases ).test( "Test", function(params) {

test/test.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ <h4 id="currentTest"></h4>
7474
</div>
7575

7676
<div id="done"><h3>Scroll down to view the log.</h3></div>
77+
78+
<div id="saveContainer">
79+
<button id="saveButton">Save test results</button>
80+
<br/><br/>
81+
Saves test results in JUnit-compatible format<br/>
82+
(Not supported in IE - other browsers may vary)
83+
</div>
7784
</div>
7885

7986
<div id="qunit"></div>

0 commit comments

Comments
 (0)