Permalink
Browse files

No ticket: speedup test suite. Close gh-1020.

  • Loading branch information...
1 parent 8773067 commit 517846aad247aa3677d156aa426f71b8dcacdcf7 @gibson042 gibson042 committed Nov 8, 2012
Showing with 223 additions and 264 deletions.
  1. +3 −6 test/unit/ajax.js
  2. +72 −75 test/unit/effects.js
  3. +138 −174 test/unit/manipulation.js
  4. +10 −9 test/unit/queue.js
View
@@ -1481,9 +1481,7 @@
jQuery.getScript( url("data/test.js"), function( data, _, jqXHR ) {
equal( foobar, "bar", "Check if script was evaluated" );
strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script (#8082)" );
- setTimeout(function() {
- start();
- }, 1000 );
+ start();
});
});
@@ -2221,7 +2219,7 @@
test( "jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() {
var passed = 0;
- expect( 1 );
+ expect( 2 );
stop();
@@ -2230,9 +2228,8 @@
});
var pass = function() {
- passed++;
+ ok( passed++ < 2, "Error callback executed" );
if ( passed == 2 ) {
- ok( true, "Check local and global callbacks after timeout" );
jQuery("#qunit-fixture").unbind("ajaxError");
start();
}
View
@@ -695,14 +695,13 @@ test("stop(clearQueue, gotoEnd)", function() {
asyncTest( "stop( queue, ..., ... ) - Stop single queues", function() {
expect( 3 );
- var foo = jQuery( "#foo" ),
- saved;
+ var saved,
+ foo = jQuery("#foo").css({ width: 200, height: 200 });
- foo.css( "width", 200 ).css( "height", 200 );
foo.animate({
width: 400
},{
- duration: 1000,
+ duration: 500,
complete: function() {
equal( parseFloat( foo.css("width") ), 400, "Animation completed for standard queue" );
equal( parseFloat( foo.css("height") ), saved, "Height was not changed after the second stop");
@@ -715,7 +714,7 @@ asyncTest( "stop( queue, ..., ... ) - Stop single queues", function() {
},{
duration: 1000,
queue: "height"
- }).dequeue( "height" ).stop( "height", false, true );
+ }).dequeue("height").stop( "height", false, true );
equal( parseFloat( foo.css("height") ), 400, "Height was stopped with gotoEnd" );
@@ -745,16 +744,6 @@ test("toggle()", function() {
ok( x.is(":visible"), "is visible again" );
});
-jQuery.checkOverflowDisplay = function(){
- var o = jQuery.css( this, "overflow" );
-
- equal(o, "visible", "Overflow should be visible: " + o);
- equal(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
-
- jQuery(this).remove();
- start();
-};
-
test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", 7, function() {
var div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ).css({
color: "#ABC",
@@ -809,29 +798,31 @@ test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", 7, function() {
jQuery( div ).remove();
});
-test("JS Overflow and Display", function() {
- expect(2);
+test("Overflow and Display", function() {
+ expect(4);
stop();
- jQuery.makeTest( "JS Overflow and Display" )
- .addClass("widewidth")
- .css({ overflow: "visible", display: "inline" })
- .addClass("widewidth")
- .text("Some sample text.")
- .before("text before")
- .after("text after")
- .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
-});
-test("CSS Overflow and Display", function() {
- expect(2);
- stop();
- jQuery.makeTest( "CSS Overflow and Display" )
- .addClass("overflow inline")
+ var
+ testClass = jQuery.makeTest("Overflow and Display")
+ .addClass("overflow inline"),
+ testStyle = jQuery.makeTest("Overflow and Display (inline style)")
+ .css({ overflow: "visible", display: "inline" }),
+ remaining = 2,
+ done = function() {
+ equal( jQuery.css( this, "overflow" ), "visible", "Overflow should be 'visible'" );
+ equal( jQuery.css( this, "display" ), "inline", "Display should be 'inline'" );
+
+ if ( --remaining === 0 ) {
+ start();
+ }
+ };
+
+ testClass.add( testStyle )
.addClass("widewidth")
.text("Some sample text.")
.before("text before")
.after("text after")
- .animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
+ .animate({ opacity: 0.5 }, "slow", done );
});
jQuery.each({
@@ -1126,57 +1117,63 @@ test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function ()
});
});
-jQuery.expandedEach = jQuery.each;
-jQuery.expandedEach({
- "slideToggle": function( $elem ) {
- return parseFloat( $elem.css("height") );
- },
- "fadeToggle": function( $elem ) {
- return $elem.css("opacity");
- },
- "toggle": function( $elem ) {
- return parseFloat( $elem.css("width") );
- }
-},
-function( method, defProp ) {
- test( method + "().stop()." + method + "()", function() {
- expect( 8 );
+test( "interrupt toggle", function() {
+ expect( 24 );
+ stop();
- var animTime = 2000;
+ var longDuration = 2000,
+ shortDuration = 500,
+ remaining = 0,
+ $elems = jQuery(".chain-test"),
+ finish = function() {
+ if ( !(--remaining) ) {
+ start();
+ }
+ };
- jQuery.each([ "in", "out" ], function( i, type ) {
- var $elem = jQuery( "#" + method.toLowerCase() + type ),
- startVal = defProp( $elem );
+ jQuery.each( { slideToggle: "height", fadeToggle: "opacity", toggle: "width" }, function( method, prop ) {
+ var $methodElems = $elems.filter( "[id^='" + method.toLowerCase() + "']" ).each(function() {
+ // Don't end test until we're done with this element
+ remaining++;
- $elem[ method ]( animTime );
- stop();
+ // Save original property value for comparison
+ jQuery.data( this, "startVal", jQuery( this ).css( prop ) );
- setTimeout( function() {
- $elem.stop();
+ // Expect olddisplay data from our .hide() call below
+ QUnit.expectJqData( this, "olddisplay" );
+ });
- notEqual( defProp( $elem ), startVal, ".stop() is called about halfway through animation." );
+ // Interrupt a hiding toggle
+ $methodElems[ method ]( longDuration );
+ setTimeout(function() {
+ $methodElems.stop().each(function() {
+ notEqual( jQuery( this ).css( prop ), jQuery.data( this, "startVal" ), ".stop() before completion of hiding ." + method + "() - #" + this.id );
+ });
- $elem[ method ](animTime, function() {
- equal( defProp( $elem ), startVal, "After doing .stop() halfway through hide, check that state has been saved for returning to original property value." );
+ // Restore
+ $methodElems[ method ]( shortDuration, function() {
+ var id = this.id,
+ $elem = jQuery( this ),
+ startVal = $elem.data("startVal");
- // Start from hidden position to show this time
- $elem.hide()[ method ]( animTime );
- setTimeout( function() {
- $elem.stop();
+ $elem.removeData("startVal");
- notEqual( defProp( $elem ), startVal, ".stop() is called about halfway through animation." );
+ equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id );
- $elem[ method ](animTime, function() {
- equal( defProp( $elem ), startVal, "After doing .stop() halfway through show, check that state has been saved for returning to original property value." );
+ // Interrupt a showing toggle
+ $elem.hide()[ method ]( longDuration );
+ setTimeout(function() {
+ $elem.stop();
+ notEqual( $elem.css( prop ), startVal, ".stop() before completion of showing ." + method + "() - #" + id );
- // Tolerate olddisplay data from .hide() call
- QUnit.expectJqData( this, "olddisplay" );
- start();
- });
- }, animTime / 2);
- });
- }, animTime / 2);
- });
+ // Restore
+ $elem[ method ]( shortDuration, function() {
+ equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id );
+ finish();
+ });
+ }, shortDuration );
+ });
+ }, shortDuration );
});
});
@@ -1319,7 +1316,7 @@ test( "animate properties missing px w/ opacity as last (#9074)", 2, function()
notEqual( l, 200, "Left is not 200 after partial animate" );
div.stop().remove();
start();
- }, 1000);
+ }, 500);
});
test("callbacks should fire in correct order (#9100)", function() {
@@ -1663,7 +1660,7 @@ asyncTest( "multiple unqueued and promise", 4, function() {
}).animate({
top: 100
}, {
- duration: 1500,
+ duration: 1000,
queue: false,
complete: function() {
strictEqual( step++, 3, "Step 3" );
Oops, something went wrong.

0 comments on commit 517846a

Please sign in to comment.