Test::WWW::Jasmine - Run Jasmine test specs for JavaScript from Perl
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', selenium => $custom_selenium_object, ); $jasmine->run();
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.
Creates a new instance of Jasmine runner. Accepts the following arguments:
Filesystem path to Jasmine spec file.
Jasmine spec script; this option is mutually exclusive with spec_file.
URL to Jasmine library, jasmine.js.
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
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
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.
This method reads test spec, generates HTML with embedded spec and runner JavaScript, stores it to html_dir and runs it through browser.
Jasmine test specs are ordinary JavaScript, but Test::WWW::Jasmine adds two keywords that can be used to include CSS stylesheets and other scripts:
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.
@css /path/to/stylesheet.css
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.
@script /path/to/script.js
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.
@script
You can place any word character (x by convention) before keyword to disable it temporarily.
Test::WWW::Jasmine depends on the following modules: Test::WWW::Selenium.
For more information on Jasmine and JavaScript testing, see https://github.com/pivotal/jasmine/wiki.
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. :)
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.
Alexander Tokarev <tokarev@cpan.org>
I would like to thank IntelliSurvey, Inc for sponsoring my work on this module.
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.
To install Test::WWW::Jasmine, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::WWW::Jasmine
CPAN shell
perl -MCPAN -e shell install Test::WWW::Jasmine
For more information on module installation, please visit the detailed CPAN module installation guide.