NAME

Test::WWW::Jasmine - Run Jasmine test specs for JavaScript from Perl

SYNOPSIS

Write Jasmine test spec:

/*
 * @css /path/to/stylesheet.css
 * @script /path/to/script.js
 */

describe('test suite', function() {
    it('should run tests', function() {
        expect(true).toBeTruthy();
        expect(false).toBeFalsy();
    });
});

Run Test::WWW::Jasmine:

use Test::WWW::Jasmine;

my $jasmine = Test::WWW::Jasmine->new(
    spec_file   => '/filesystem/path/to/test/spec.js',
    jasmine_url => 'http://myserver/jasmine/jasmine.js',
    html_dir    => '/filesystem/path/to/htdocs/test',
    browser_url => 'http://myserver/test',
);

$jasmine->run();

DESCRIPTION

This module implements Perl test runner for JavaScript test specs that use Jasmine BDD framework. Test::WWW::Jasmine uses WWW::Selenium to run tests in a browser, thus making possible to test complex JavaScript applications that rely heavily on DOM availability.

Test spec output is collected and converted to TAP format; from Perl perspective Jasmine test specs look just like ordinary Perl tests.

METHODS

new(%params)

Creates a new instance of Jasmine runner. Accepts the following arguments:

spec_file

Filesystem path to Jasmine spec file.

spec_script

Jasmine spec script; this option is mutually exclusive with spec_file.

jasmine_url

URL to Jasmine library, jasmine.js.

html_dir

Filesystem path to directory that is within www root and is writeable to Jasmine runner. For each test script, an HTML file is generated and placed to this directory; the file URL is then fed to Selenium to run in browser.

Example: /var/www/htdocs/test

browser_url

URL that points to the html_dir via HTTP server. This URL will be used to run HTML with test spec in browser.

Example: http://localhost/test

selenium

If you don't want Test::WWW::Selenium to instantiate a new WWW::Selenium object, pass it as constructor argument. It is especially useful when you want to control Selenium options, or use remote testing provider like Sauce Labs, etc.

run

This method reads test spec, generates HTML with embedded spec and runner JavaScript, stores it to html_dir and runs it through browser.

TEST SPEC FORMAT

Jasmine test specs are ordinary JavaScript, but Test::WWW::Jasmine adds two keywords that can be used to include CSS stylesheets and other scripts:

@css

Use this keyword as @css /path/to/stylesheet.css to include stylesheets. For each @css sheet, a <link> tag will be added to HTML head.

@script

Use this keyword as @script /path/to/script.js to include additional JavaScript. Each script will be downloaded by test runner (in browser) and eval'ed.

Place these keywords in comment section near the top of the spec. Any whitespace and usual decorations like '*' before @css/@script will be ignored.

Note that @script keywords are processed synchronously; each script is downloaded and eval'ed at the time @script keyword is encountered. This matches usual browser behavior; it also means that the test spec JavaScript itself will be evaluated *after* all @scripts are processed.

DEPENDENCIES

Test::WWW::Jasmine depends on the following modules: WWW::Selenium.

SEE ALSO

For more information on Jasmine and JavaScript testing, see https://github.com/pivotal/jasmine/wiki.

CAVEATS

Perl interpreter running Test::WWW::Jasmine should have access to a directory that is accessible via http. This implies an HTTP server already installed and configured, which shouldn't be a big problem by the time when you start writing JavaScript tests. :)

BUGS AND LIMITATIONS

There are undoubtedly lots of bugs in this module. Use github tracker to report them (the best way) or just drop me an e-mail. Patches are welcome.

AUTHOR

Alexander Tokarev <tokarev@cpan.org>

ACKNOWLEDGEMENTS

I would like to thank IntelliSurvey, Inc for sponsoring my work on this module.

COPYRIGHT AND LICENSE

Copyright (c) 2012 Alexander Tokarev.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.