Home page Forum Wiki Mail Jabber Devel NIX-FILES

AltLUG Git

Git-repositories of Altai Linux User Group

Cleanup composite addon: Use callback registration instead of overwriting them. Set...
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Sat, 21 Apr 2012 12:38:21 +0000 (14:38 +0200)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Sat, 21 Apr 2012 12:38:21 +0000 (14:38 +0200)
addons/composite/composite-demo-test.html
addons/composite/composite-test.html [deleted file]
addons/composite/composite-test.js [deleted file]
addons/composite/dummy-qunit-test.html [deleted file]
addons/composite/dummy-same-test.html [deleted file]
addons/composite/index.html
addons/composite/qunit-composite.js

index 9740445..ad964c9 100644 (file)
@@ -14,8 +14,7 @@
                "../../test/index.html",
                "../canvas/canvas.html",
                "../close-enough/close-enough.html",
-               "../step/step.html",
-               "composite-test.html"
+               "../step/step.html"
        ]);
        </script>
 </head>
diff --git a/addons/composite/composite-test.html b/addons/composite/composite-test.html
deleted file mode 100644 (file)
index 5240564..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-       <meta charset="UTF-8" />
-       <title>QUnit Core Test Suite</title>
-       <link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen">
-       <script src="../../qunit/qunit.js"></script>
-
-       <script src="qunit-composite.js"></script>
-       <script src="composite-test.js"></script>
-</head>
-<body>
-       <div id="qunit"></div>
-       <div id="qunit-fixture">test markup</div>
-</body>
-</html>
diff --git a/addons/composite/composite-test.js b/addons/composite/composite-test.js
deleted file mode 100644 (file)
index c2a251d..0000000
+++ /dev/null
@@ -1,159 +0,0 @@
-module( "testSuites tests", (function(){
-       var asyncTest = QUnit.asyncTest,
-               runSuite = QUnit.runSuite;
-
-       return {
-               setup: function(){
-                       //proxy asyncTest and runSuite
-                       QUnit.asyncTest = window.asyncTest = function( name, callback ){
-                               ok( true, "asyncTestCalled for each suite" );
-                               callback(); //don't acutally create tests, just call callback
-                       };
-                       QUnit.runSuite = window.runSuite = function(){
-                               ok( true, "runSuite called for each suite" );
-                       };
-                       //ensure that subsuite's done doesn't run
-                       this.oldDone = QUnit.done;
-               },
-               teardown: function(){
-                       //restore
-                       QUnit.asyncTest = window.asyncTest = asyncTest;
-                       QUnit.runSuite = window.runSuite = runSuite;
-                       QUnit.done = this.oldDone;
-               }
-       };
-})());
-
-test( "proper number of asyncTest and runSuite calls", function(){
-       expect( 6 );
-       QUnit.testSuites( ["one.html", "two.html", "three.html"] );
-});
-
-test( "done callback changed", function(){
-       QUnit.testSuites( ["dummy.html"] );
-       notEqual( this.oldDone, QUnit.done, "done callback should be set" );
-});
-
-module( "testStart tests", (function(){
-       var id = QUnit.id;
-       return {
-               setup: function(){
-                       //proxy id
-                       var fakeElem = this.fakeElem = document.createElement( "div" );
-
-                       QUnit.id = function(){
-                               return fakeElem;
-                       }
-               },
-               teardown: function(){
-                       QUnit.id = id;
-               }
-       };
-})());
-
-test( "running message printed", function(){
-       var hello = "hello world",
-       expected = "Running " + hello + "...<br>&nbsp;";
-       QUnit.testStart( {name: hello} );
-       equal( this.fakeElem.innerHTML, expected, "innerHTML was set correctly by testStart" );
-});
-
-module( "testDone tests", (function(){
-       var id = QUnit.id;
-       return {
-               setup: function(){
-                       //proxy id
-                       var fakeElem = this.fakeElem = document.createElement( "div" );
-                       fakeElem.appendChild( document.createElement( "ol" ) );
-                       fakeElem.appendChild( document.createElement( "ol" ) );
-                       QUnit.id = function(){
-                               return fakeElem;
-                       }
-               },
-               teardown: function(){
-                       QUnit.id = id;
-               }
-       };
-})());
-
-test( "test expansions are hidden", function(){
-       QUnit.testDone();
-       equal( this.fakeElem.children[0].style.display, "none", "first ol display is none" );
-       equal( this.fakeElem.children[1].style.display, "none", "second ol display is none" );
-});
-
-test( "non-ol elements aren't hidden", function(){
-       this.fakeElem.appendChild( document.createElement( "span" ) );
-
-       QUnit.testDone();
-       notEqual( this.fakeElem.children[2].style.display, "none", "first ol display is none" );
-});
-
-module( "runSuite tests", (function(){
-       var getElementsByTagName = document.getElementsByTagName,
-               createElement = document.createElement,
-               runSuite = QUnit.runSuite;
-
-       return {
-               setup: function(){
-                       //proxy getElementsByTagName and createElement
-                       var setAttributeCall = this.setAttributeCall = {},
-                               appendChildCall = this.appendChildCall = {called: 0},
-                               iframeLoad = this.iframeLoad = {},
-                               iframeQUnitObject = this.iframeQUnitObject = {},
-                               fakeElement = {
-                                       appendChild: function(){appendChildCall.called++},
-                                       setAttribute: function(){setAttributeCall.args = arguments},
-                                       addEventListener: function( type, callback ){iframeLoad.callback = callback;},
-                                       contentWindow: {QUnit: iframeQUnitObject},
-                                       className: "",
-                               };
-
-                       document.getElementsByTagName = function(){
-                               return [fakeElement];
-                       };
-                       document.createElement = function(){
-                               return fakeElement;
-                       }
-
-               },
-               teardown: function(){
-                       document.getElementsByTagName = getElementsByTagName;
-                       document.createElement = createElement;
-                       //must restore even though we didn't proxy; the runner overwrites upon first call
-                       QUnit.runSuite = runSuite;
-               }
-       };
-})());
-
-test( "runSuite different after first run", function(){
-       var before = QUnit.runSuite,
-               after;
-       QUnit.runSuite();
-       after = QUnit.runSuite;
-       notEqual( before, after, "runSuite changed after initial run" );
-});
-
-test( "iframe only created once", function(){
-       QUnit.runSuite();
-       equal( this.appendChildCall.called, 1, "append child called once" );
-       QUnit.runSuite();
-       equal( this.appendChildCall.called, 1, "append child only ever called once" );
-});
-
-test( "iframe's QUnit object is modified when iframe source loads", function(){
-       var before = this.iframeQUnitObject,
-               after;
-       QUnit.runSuite();
-       this.iframeLoad.callback();
-       notEqual( before, after, "iframe's qunit object is modified upon load");
-});
-
-test( "iframe src set to suite passed", function(){
-       var pages = ["testing.html", "subsuiteRunner.html"];
-       QUnit.runSuite( pages[0] );
-       equal( this.setAttributeCall.args[0], "src", "src attribute set" );
-       equal( this.setAttributeCall.args[1], pages[0], "src attribute set" );
-       QUnit.runSuite( pages[1] );
-       equal( this.setAttributeCall.args[1], pages[1], "src attribute set" );
-});
\ No newline at end of file
diff --git a/addons/composite/dummy-qunit-test.html b/addons/composite/dummy-qunit-test.html
deleted file mode 100644 (file)
index 6ca3d0b..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-       <meta charset="UTF-8" />
-       <title>QUnit Core Test Suite</title>
-       <link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen">
-       <script src="../../qunit/qunit.js"></script>
-
-       <script src="../../test/test.js"></script>
-</head>
-<body>
-       <div id="qunit"></div>
-       <div id="qunit-fixture">test markup</div>
-</body>
-</html>
diff --git a/addons/composite/dummy-same-test.html b/addons/composite/dummy-same-test.html
deleted file mode 100644 (file)
index 1a64808..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-       <meta charset="UTF-8" />
-       <title>QUnit Same Test Suite</title>
-       <link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen">
-       <script src="../../qunit/qunit.js"></script>
-
-       <script src="../../test/deepEqual.js"></script>
-</head>
-<body>
-       <div id="qunit"></div>
-       <div id="qunit-fixture">test markup</div>
-</body>
-</html>
index 4d2e85a..b08f5e9 100644 (file)
@@ -26,10 +26,8 @@ QUnit.testSuites([
 ]);
                </pre>
                <h4>Tests</h4>
-               <p>Composite has tests of it's own.</p>
                <p>
-                       <a href="composite-test.html">Composite Test</a>: A suite which tests the implementation of composite.<br>
-                       <a href="composite-demo-test.html">Composite Demo</a>: A suite which demoes how Compisite is bootstrapped and run.
+                       <a href="composite-demo-test.html">Composite Demo</a>: A suite which demoes how Composite is bootstrapped and run.
                </p>
        </body>
 </html>
index 232cabe..5b753e2 100644 (file)
@@ -2,7 +2,9 @@
 
 QUnit.extend( QUnit, {
        testSuites: function( suites ) {
-               QUnit.initIframe();
+               QUnit.begin(function() {
+                       QUnit.initIframe();
+               });
 
                for ( var i = 0; i < suites.length; i++ ) {
                        (function( suite ) {
@@ -11,39 +13,9 @@ QUnit.extend( QUnit, {
                                });
                        }( suites[i] ) );
                }
-               QUnit.done = function() {
+               QUnit.done(function() {
                        this.iframe.style.display = "none";
-               };
-       },
-
-       testStart: function( data ) {
-               // update the test status to show which test suite is running
-               QUnit.id( "qunit-testresult" ).innerHTML = "Running " + data.name + "...<br>&nbsp;";
-       },
-
-       testDone: function() {
-               var current = QUnit.id( this.config.current.id ),
-                       children = current.children,
-                       iframe = this.iframe;
-
-               // undo the auto-expansion of failed tests
-               for ( var i = 0; i < children.length; i++ ) {
-                       if ( children[i].nodeName === "OL" ) {
-                               children[i].style.display = "none";
-                       }
-               }
-
-               QUnit.addEvent(current, "dblclick", function( e ) {
-                       var target = e && e.target ? e.target : window.event.srcElement;
-                       if ( target.nodeName.toLowerCase() == "span" || target.nodeName.toLowerCase() == "b" ) {
-                               target = target.parentNode;
-                       }
-                       if ( window.location && target.nodeName.toLowerCase() === "strong" ) {
-                               window.location = iframe.src;
-                       }
                });
-
-               current.getElementsByTagName('a')[0].href = iframe.src;
        },
 
        runSuite: function( suite ) {
@@ -62,28 +34,33 @@ QUnit.extend( QUnit, {
                        var module, test,
                                count = 0;
 
-                       QUnit.extend( iframeWin.QUnit, {
-                               moduleStart: function( data ) {
-                                       // capture module name for messages
-                                       module = data.name;
-                               },
-
-                               testStart: function( data ) {
-                                       // capture test name for messages
-                                       test = data.name;
-                               },
-
-                               log: function( data ) {
-                                       // pass all test details through to the main page
-                                       var message = module + ": " + test + ": " + data.message;
-                                       expect( ++count );
-                                       QUnit.push( data.result, data.actual, data.expected, message );
-                               },
-
-                               done: function() {
-                                       // start the wrapper test from the main page
-                                       start();
+
+                       iframeWin.QUnit.moduleStart(function( data ) {
+                               // capture module name for messages
+                               module = data.name;
+                       });
+
+                       iframeWin.QUnit.testStart(function( data ) {
+                               // capture test name for messages
+                               test = data.name;
+                       });
+                       iframeWin.QUnit.testDone(function() {
+                               test = null;
+                       });
+
+                       iframeWin.QUnit.log(function( data ) {
+                               if (test === null) {
+                                       return;
                                }
+                               // pass all test details through to the main page
+                               var message = module + ": " + test + ": " + data.message;
+                               expect( ++count );
+                               QUnit.push( data.result, data.actual, data.expected, message );
+                       });
+
+                       iframeWin.QUnit.done(function() {
+                               // start the wrapper test from the main page
+                               start();
                        });
                }
                QUnit.addEvent( iframe, "load", onIframeLoad );
@@ -91,4 +68,35 @@ QUnit.extend( QUnit, {
                iframeWin = iframe.contentWindow;
        }
 });
+
+QUnit.testStart(function( data ) {
+       // update the test status to show which test suite is running
+       QUnit.id( "qunit-testresult" ).innerHTML = "Running " + data.name + "...<br>&nbsp;";
+});
+
+QUnit.testDone(function() {
+       var current = QUnit.id( this.config.current.id ),
+               children = current.children,
+               src = this.iframe.src;
+
+       // undo the auto-expansion of failed tests
+       for ( var i = 0; i < children.length; i++ ) {
+               if ( children[i].nodeName === "OL" ) {
+                       children[i].style.display = "none";
+               }
+       }
+
+       QUnit.addEvent(current, "dblclick", function( e ) {
+               var target = e && e.target ? e.target : window.event.srcElement;
+               if ( target.nodeName.toLowerCase() == "span" || target.nodeName.toLowerCase() == "b" ) {
+                       target = target.parentNode;
+               }
+               if ( window.location && target.nodeName.toLowerCase() === "strong" ) {
+                       window.location = src;
+               }
+       });
+
+       current.getElementsByTagName('a')[0].href = src;
+});
+
 }( QUnit ) );

Hosting is provided AltSPAHow to use Git
Please direct any questions on jabber alex.wolf@jabber.ru

Valid HTML 4.0 Transitional Valid CSS!

Designer Alexander Wolf