[Bps-public-commit] test-javascript-qunit branch, master, updated. 60ee4c4da46225bfd2e33e240d03d89598aa48ac

jesse jesse at bestpractical.com
Mon Feb 8 12:30:43 EST 2010


The branch, master has been updated
       via  60ee4c4da46225bfd2e33e240d03d89598aa48ac (commit)
      from  83f2d5836cb702e3382aa13dbc0ecfd44a7c8ad1 (commit)

Summary of changes:
 README               |   19 +++++++++++++++++++
 bin/qunit_harness.pl |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 js/qunit-tap.js      |   36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 105 insertions(+), 0 deletions(-)
 create mode 100644 README
 create mode 100644 bin/qunit_harness.pl
 create mode 100644 js/qunit-tap.js

- Log -----------------------------------------------------------------
commit 60ee4c4da46225bfd2e33e240d03d89598aa48ac
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Mon Feb 8 09:30:37 2010 -0800

    Initial commit

diff --git a/README b/README
new file mode 100644
index 0000000..2afa843
--- /dev/null
+++ b/README
@@ -0,0 +1,19 @@
+This is a very trivial harness around qunit which, with a bit of setup
+allows you to use tools built for TAP (the Test Anything Protocol)
+and the Perl testing toolchain to run a QUnit test suite from the unix
+commandline.
+
+To make it go, you'll want to include the "qunit-tap.js" Javascript in your
+QUnit test harness index.html just after you include "qunit.js".
+
+You'll need to take the bin/qunit_harness.pl and tweak it to know where to find your QUnit test suite. 
+
+You'll probably also need to configure how it launches the  harnessed web browser. 
+
+Patches are most certainly welcome.
+
+-Jesse Vincent <jesse at bestpractical.com>
+
+Copyright 2010 Best Practical Solutions, LLC
+
+You may redistribute this software under either the GNU General Public License or Perl's Artistic License (v1).
diff --git a/bin/qunit_harness.pl b/bin/qunit_harness.pl
new file mode 100644
index 0000000..7ae134f
--- /dev/null
+++ b/bin/qunit_harness.pl
@@ -0,0 +1,50 @@
+#!/usr/bin/env perl
+
+use warnings;
+use strict;
+
+
+my %args = (@ARGV);
+my $port = $args{'--port'};
+my $url = "http://localhost:8008/static/honeycomb/test/index.html";
+my $server = QunitServer->new( $port || (10000 + int(rand(10000))));
+$server->run();
+
+
+package QunitServer;
+use base 'HTTP::Server::Simple::CGI';
+use Data::Dumper;
+
+sub print_banner {
+    my $self = shift;
+    $self->run_browser();
+}
+
+sub run_browser {
+    my $self = shift;
+    my $command =  "chromium-browser ".$url."#".$self->port;
+    `($command)&`;
+}
+
+our $counter;
+
+sub handle_request {
+    my $self = shift;
+    my $cgi = shift;
+    my $result;
+    if ($cgi->param('type') eq 'startup') {
+        $self->stdio_handle->print( "200 OK\n\nOK");
+    }
+    if ($cgi->param('type') eq 'one-test'){
+        print "".( $cgi->param('result')? 'ok':'not ok') . " " .++$counter . " " .$cgi->param('message')."\n";
+    } elsif ($cgi->param('type') eq 'done'){ 
+        my $result = $cgi->param('done');
+        print "1..".$cgi->param('total')."\n"; # crosschecking with the counter on the other side
+        exit( $cgi->param('fail') ? 1 : 0);
+    }
+}
+
+sub stdout_handle {
+    return *STDOUT;
+}
+
diff --git a/js/qunit-tap.js b/js/qunit-tap.js
new file mode 100644
index 0000000..6135610
--- /dev/null
+++ b/js/qunit-tap.js
@@ -0,0 +1,36 @@
+// Get the port from the url fragment
+var port = parseInt(document.location.hash.substring(1));
+
+if (port > 0) {
+//
+//QUnit.tapServerReady = false;
+//
+//QUnit.testStart = function (name) {
+//    if (QUnit.tapServerReady == false) {
+//        
+//        $.get( {
+//    
+//        "url": "http://localhost:"+port+"/", 
+//        "async": false,
+//        "cache": false,
+//        "type": "GET",
+//        "data": { "type":"startup"},
+//        "success": function(xhr, msg) {
+//            if (msg === 'success') {
+//                QUnit.tapServerReady = true;
+//            }
+//        }
+//        });
+//    };
+//
+//};
+//
+//
+
+QUnit.log = function (result, message) { $.get("http://localhost:"+port, { "type": "one-test", "result": result, "message":message});
+};
+
+QUnit.done = function (failures, total) { $.get("http://localhost:"+port, { "type": "done", "total": total, "fail": failures}); };
+
+}
+

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list