fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-02-22 02:29 pm

[dw-free] Framework for JS unit tests

[commit: http://hg.dwscoalition.org/dw-free/rev/8daecda810b9]

http://bugs.dwscoalition.org/show_bug.cgi?id=3524

Automatically only run the tests applicable to a library, when it's provided
in the path (and you don't override using URL parameters). So instead of
doing: /dev/tests/sample/jquery?jquery to automatically load jquery
libraries and run only jquery tests, we can do /dev/tests/jquery.

Patch by [personal profile] fu.

Files modified:
  • views/dev/tests.tt
  • views/dev/tests/sample.js
--------------------------------------------------------------------------------
diff -r 5cad96087a9a -r 8daecda810b9 views/dev/tests.tt
--- a/views/dev/tests.tt	Tue Feb 22 17:43:00 2011 +0800
+++ b/views/dev/tests.tt	Tue Feb 22 22:29:33 2011 +0800
@@ -53,6 +53,15 @@ stc/blah.css
 
 -->
 <script type="text/javascript">
+if ( ! location.search ) {
+    var lib = "[% testlib %]";
+
+    QUnit.config.filters = [ "*" ];
+    if ( lib ) {
+        QUnit.config.filters.push( lib );
+    }
+}
+
 [% IF testlib == "jquery" %]
     $(document).ready(function(){
         [% tests %]
diff -r 5cad96087a9a -r 8daecda810b9 views/dev/tests/sample.js
--- a/views/dev/tests/sample.js	Tue Feb 22 17:43:00 2011 +0800
+++ b/views/dev/tests/sample.js	Tue Feb 22 22:29:33 2011 +0800
@@ -27,6 +27,11 @@ stc/sample.css
     Each test suite can be separated into modules, and you can filter to
     specific modules by appending ?modulename1&modulename2 to the path. You can
     also filter to specific matching test names in the same way.
+
+
+    If you don't filter to a specific module, then the tests will automatically
+    run the module matching your current desired library (if provided), and all
+    modules whose name begins with a "*".
 
  =============================================================================*/
 module( "jquery" );
@@ -46,14 +51,14 @@ test( "checking included html (sample.ht
 });
 
 
-module( "foo" );
+module( "*foo" );
 test( "example test foo", function() {
     expect(1);
 
     ok( true, "passed" );
 });
 
-test( "example test again", function() {
+test( "*example test again", function() {
     expect(1);
 
     ok( true, "passed again" );
--------------------------------------------------------------------------------