Test.Harness.Browser - Run TAP standard JavaScript test scripts with statistics in a Browser
<html>
<head>
<script type="text/javascript" src="JSAN.js"></script>
</head>
<body>
<script type="text/javascript">
new JSAN("../lib").use("Test.Harness.Browser");
new Test.Harness.Browser('JSAN.js').runTests(
'async.js',
'bad_plan.html',
'buffer.js',
'builder.html'
);
</script>
</body>
</html>
STOP! If all you want to do is write a test script, consider using Test.Simple. Test.Harness is the module that reads the output from Test.Simple, Test.More and other modules based on Test.Builder. You don't need to know about Test.Harness to use those modules.
Test.Harness.Browser runs JavaScript tests in a browser and expects to get the results from the TestResults
attribute of the Test.Builder object constructed by each test script. These results conform to a format called TAP, the Test Anything Protocol. It is defined in http://search.cpan.org/dist/Test-Harness/lib/Test/Harness/TAP.pod. See Test.Harness for details on the output.
Test.Harness.Browser.runTests('testone.js', 'testtwo.html');
Constructs a new Test.Harness.Browser object and calls its runTests()
instance method, passing all arguments along.
var harness = new Test.Harness.Browser('script.js', 'another.js');
Constructs a new Test.Harness.Browser object. If your tests will be pure JavaScript files (that is, ending in .js, pass in a list of dependency scripts to be loaded before each script. A particularly handy one to load is JSAN.js (http://www.openjsan.org/go?l=JSAN). This library will allow you to dymamically load whatever other libraries you need from each test script, like so:
var jsan = new JSAN('../lib');
jsan.use('Test.More');
jsan.use('HTTP.Query');
plan({tests: 1});
var q = new HTTP.Query;
isaOK(q, HTTP.Query);
In fact, this is the approach that Test.Simple's own tests take. Check 'em out!
harness.runTests('testone.js', 'testtwo.html');
TestResults
attribute of their global Test.Builder.Test
object. It prints out each individual test that failed along with a summary report and a how long it all took. When all tests have been run, a diagnostic message will be output. See Test.Harness for details on the output.An HTML file that uses Test.Harness.Browser will automatically process the GET
its arguments, and these can be used to affect the behavior of the harness.
index.html?verbose=1
verbose
option to a true value to have all of the output of all of the tests in the harness output to the browser window. By default, only failing tests display their output. index.html?file=foo.html;file=bar.html
file
option to override the list of files passed to runTest(). This option may be specified multiple times, and each file specified will be passed to runTest().Safari (and maybe KHTML?) has a number of bugs that affect how Test.Harness.Browser works. The most obvious is that it cannot run tests on a local disk. The harness only works in Safari if the tests are served by a Web server. The WebKit team is aware of the issue; expect it to be fixed in a future version.
Other Safari bugs I reported while writing this module:
Test.Harness, the base class for this class.
Test.Simple and Test.More, modules with which to write tests.
David Wheeler <david@kineticode.com>.
Copyright 2005 by David Wheeler <david@kineticode.com>
This program is free software; you can redistribute it and/or modify it under the terms of the Perl Artistic License or the GNU GPL.
See http://www.perl.com/perl/misc/Artistic.html and http://www.gnu.org/copyleft/gpl.html.