return false;
}
})()
-}
+};
var testId = 0;
b.innerHTML = "Running " + this.name;
var li = document.createElement("li");
li.appendChild( b );
+ li.className = "running";
li.id = this.id = "test-output" + testId++;
tests.appendChild( li );
}
}
// store result when possible
- defined.sessionStorage && sessionStorage.setItem("qunit-" + this.testName, bad);
+ if ( QUnit.config.reorder && defined.sessionStorage ) {
+ if (bad) {
+ sessionStorage.setItem("qunit-" + this.module + "-" + this.testName, bad)
+ } else {
+ sessionStorage.removeItem("qunit-" + this.testName);
+ }
+ }
if (bad == 0) {
ol.style.display = "none";
var b = document.createElement("strong");
b.innerHTML = this.name + " <b class='counts'>(<b class='failed'>" + bad + "</b>, <b class='passed'>" + good + "</b>, " + this.assertions.length + ")</b>";
+ var a = document.createElement("a");
+ a.innerHTML = "Rerun";
+ a.href = QUnit.url({ filter: getText([b]).replace(/\([^)]+\)$/, "").replace(/(^\s*|\s*$)/g, "") });
+
addEvent(b, "click", function() {
- var next = b.nextSibling, display = next.style.display;
+ var next = b.nextSibling.nextSibling,
+ display = next.style.display;
next.style.display = display === "none" ? "block" : "none";
});
target = target.parentNode;
}
if ( window.location && target.nodeName.toLowerCase() === "strong" ) {
- window.location.search = "?" + encodeURIComponent(getText([target]).replace(/\(.+\)$/, "").replace(/(^\s*|\s*$)/g, ""));
+ window.location = QUnit.url({ filter: getText([target]).replace(/\([^)]+\)$/, "").replace(/(^\s*|\s*$)/g, "") });
}
});
var li = id(this.id);
li.className = bad ? "fail" : "pass";
- li.style.display = resultDisplayStyle(!bad);
li.removeChild( li.firstChild );
li.appendChild( b );
+ li.appendChild( a );
li.appendChild( ol );
} else {
});
}
// defer when previous test run passed, if storage is available
- var bad = defined.sessionStorage && +sessionStorage.getItem("qunit-" + this.testName);
+ var bad = QUnit.config.reorder && defined.sessionStorage && +sessionStorage.getItem("qunit-" + this.module + "-" + this.testName);
if (bad) {
run();
} else {
};
}
-}
+};
var QUnit = {
}, timeout);
}
}
-
};
// Backwards compatibility, deprecated
queue: [],
// block until document ready
- blocking: true
+ blocking: true,
+
+ // by default, run previously failed tests first
+ // very useful in combination with "Hide passed tests" checked
+ reorder: true,
+
+ noglobals: false,
+ notrycatch: false
};
// Load paramaters
(function() {
var location = window.location || { search: "", protocol: "file:" },
- GETParams = location.search.slice(1).split('&');
-
- for ( var i = 0; i < GETParams.length; i++ ) {
- GETParams[i] = decodeURIComponent( GETParams[i] );
- if ( GETParams[i] === "noglobals" ) {
- GETParams.splice( i, 1 );
- i--;
- config.noglobals = true;
- } else if ( GETParams[i] === "notrycatch" ) {
- GETParams.splice( i, 1 );
- i--;
- config.notrycatch = true;
- } else if ( GETParams[i].search('=') > -1 ) {
- GETParams.splice( i, 1 );
- i--;
+ params = location.search.slice( 1 ).split( "&" ),
+ length = params.length,
+ urlParams = {},
+ current;
+
+ if ( params[ 0 ] ) {
+ for ( var i = 0; i < length; i++ ) {
+ current = params[ i ].split( "=" );
+ current[ 0 ] = decodeURIComponent( current[ 0 ] );
+ // allow just a key to turn on a flag, e.g., test.html?noglobals
+ current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true;
+ urlParams[ current[ 0 ] ] = current[ 1 ];
+ if ( current[ 0 ] in config ) {
+ config[ current[ 0 ] ] = current[ 1 ];
+ }
}
}
-
- // restrict modules/tests by get parameters
- config.filters = GETParams;
-
+
+ QUnit.urlParams = urlParams;
+ config.filter = urlParams.filter;
+
// Figure out if we're running the tests from a server or not
QUnit.isLocal = !!(location.protocol === 'file:');
})();
blocking: false,
autostart: true,
autorun: false,
- filters: [],
+ filter: "",
queue: [],
semaphore: 0
});
- var tests = id("qunit-tests"),
- banner = id("qunit-banner"),
- result = id("qunit-testresult");
+ var tests = id( "qunit-tests" ),
+ banner = id( "qunit-banner" ),
+ result = id( "qunit-testresult" );
if ( tests ) {
tests.innerHTML = "";
if ( result ) {
result.parentNode.removeChild( result );
}
+
+ if ( tests ) {
+ result = document.createElement( "p" );
+ result.id = "qunit-testresult";
+ result.className = "result";
+ tests.parentNode.insertBefore( result, tests );
+ result.innerHTML = 'Running...<br/> ';
+ }
},
/**
});
},
+ url: function( params ) {
+ params = extend( extend( {}, QUnit.urlParams ), params );
+ var querystring = "?",
+ key;
+ for ( key in params ) {
+ querystring += encodeURIComponent( key ) + "=" +
+ encodeURIComponent( params[ key ] ) + "&";
+ }
+ return window.location.pathname + querystring.slice( 0, -1 );
+ },
+
// Logging callbacks; all receive a single argument with the listed properties
// run test/logs.html for any related changes
begin: function() {},
}
var banner = id("qunit-header");
if ( banner ) {
- var paramsIndex = location.href.lastIndexOf(location.search);
- if ( paramsIndex > -1 ) {
- var mainPageLocation = location.href.slice(0, paramsIndex);
- if ( mainPageLocation == location.href ) {
- banner.innerHTML = '<a href=""> ' + banner.innerHTML + '</a> ';
- } else {
- var testName = decodeURIComponent(location.search.slice(1));
- banner.innerHTML = '<a href="' + mainPageLocation + '">' + banner.innerHTML + '</a> › <a href="">' + testName + '</a>';
- }
- }
+ banner.innerHTML = '<a href="' + QUnit.url({ filter: undefined }) + '"> ' + banner.innerHTML + '</a> ' +
+ '<label><input name="noglobals" type="checkbox"' + ( config.noglobals ? ' checked="checked"' : '' ) + '>noglobals</label>' +
+ '<label><input name="notrycatch" type="checkbox"' + ( config.notrycatch ? ' checked="checked"' : '' ) + '>notrycatch</label>';
+ addEvent( banner, "change", function( event ) {
+ var params = {};
+ params[ event.target.name ] = event.target.checked ? true : undefined;
+ window.location = QUnit.url( params );
+ });
}
var toolbar = id("qunit-testrunner-toolbar");
filter.type = "checkbox";
filter.id = "qunit-filter-pass";
addEvent( filter, "click", function() {
- var li = document.getElementsByTagName("li");
- for ( var i = 0; i < li.length; i++ ) {
- if ( li[i].className.indexOf("pass") > -1 ) {
- li[i].style.display = filter.checked ? "none" : "";
- }
+ var ol = document.getElementById("qunit-tests");
+ if ( filter.checked ) {
+ ol.className = ol.className + " hidepass";
+ } else {
+ var tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " ";
+ ol.className = tmp.replace(/ hidepass /, " ");
}
if ( defined.sessionStorage ) {
- sessionStorage.setItem("qunit-filter-passed-tests", filter.checked ? "true" : "");
+ if (filter.checked) {
+ sessionStorage.setItem("qunit-filter-passed-tests", "true");
+ } else {
+ sessionStorage.removeItem("qunit-filter-passed-tests");
+ }
}
});
if ( defined.sessionStorage && sessionStorage.getItem("qunit-filter-passed-tests") ) {
filter.checked = true;
+ var ol = document.getElementById("qunit-tests");
+ ol.className = ol.className + " hidepass";
}
toolbar.appendChild( filter );
}
if ( tests ) {
- var result = id("qunit-testresult");
-
- if ( !result ) {
- result = document.createElement("p");
- result.id = "qunit-testresult";
- result.className = "result";
- tests.parentNode.insertBefore( result, tests.nextSibling );
- }
-
- result.innerHTML = html;
+ id( "qunit-testresult" ).innerHTML = html;
}
QUnit.done( {
}
function validTest( name ) {
- var i = config.filters.length,
+ var filter = config.filter,
run = false;
- if ( !i ) {
+ if ( !filter ) {
return true;
}
-
- while ( i-- ) {
- var filter = config.filters[i],
- not = filter.charAt(0) == '!';
- if ( not ) {
- filter = filter.slice(1);
- }
+ not = filter.charAt( 0 ) === "!";
+ if ( not ) {
+ filter = filter.slice( 1 );
+ }
- if ( name.indexOf(filter) !== -1 ) {
- return !not;
- }
+ if ( name.indexOf( filter ) !== -1 ) {
+ return !not;
+ }
- if ( not ) {
- run = true;
- }
+ if ( not ) {
+ run = true;
}
return run;
}
}
-function resultDisplayStyle(passed) {
- return passed && id("qunit-filter-pass") && id("qunit-filter-pass").checked ? 'none' : '';
-}
-
function escapeHtml(s) {
if (!s) {
return "";
function extend(a, b) {
for ( var prop in b ) {
- a[prop] = b[prop];
+ if ( b[prop] === undefined ) {
+ delete a[prop];
+ } else {
+ a[prop] = b[prop];
+ }
}
return a;
error:'[ERROR]', //when no parser is found, shouldn't happen
unknown: '[Unknown]',
'null':'null',
- undefined:'undefined',
+ 'undefined':'undefined',
'function':function( fn ) {
var ret = 'function',
name = 'name' in fn ? fn.name : (reName.exec(fn)||[])[1];//functions never have name in IE
};
})();
-})(this);
\ No newline at end of file
+})(this);