NAME

Dancer::Plugin::Test::Jasmine - Inject and run Jasmine tests in your web pages

VERSION

version 0.2.0

SYNOPSIS

In config.yml:

plugins:
    'Test::Jasmine':
        specs_dir: t/specs
        prefix: /test
        lib_dir: /path/to/jasmine/dir
        additional_scripts:
            - /uri/to/script.js
        additional_css:
            - /usr/to/other.css

In application:

package MyApp;

use Dancer;

use if $ENV{DANCER_ENVIRONMENT} eq 'development', 
    'Dancer::Plugin::Test::Jasmine';

...;

DESCRIPTION

This plugin helps running Jasmine tests for your Dancer application.

If the plugin is enabled, a request with queries having one or more test fields will make the application inject the Jasmine library and the tests in the response (if no test parameter is present, the response is left untouched). The library is injected at the end of the head section of the page, and the tests at the end of its body.

To incorporate those tests to your Perl test suites, see Dancer::Plugin::Test::Jasmine::Results.

In addition to Jasmine itself, this plugin also load jasmine-jquery.

CONFIGURATION PARAMETERS

RUNNING TESTS AS PART OF PERL TEST SUITES

Obviously, the tests need to be run from within a browser with a JavaScript engine. But if you desire to have the tests included in your regular test suites, there are several test modules allowing interactions (Test::WWW::Selenium, WWW::Mechanize::PhantomJS) with browsers.

In addition of the regular HTML report, the Jasmine test results are also accessible via the JavaScipt function jasmine.getJSReportAsString(), thanks to the Jasmine-jsreporter plugin. The module Dancer::Plugin::Test::Jasmine::Results provides a helper function jasmine_results that takes in the Jasmine results, and produce equivalent TAP output.

WWW::Mechanize::PhantomJS

For example, if we wanted to run the test 't/specs/verify_title.js' via PhantomJS, we could use:

use strict;
use warnings;

use Test::More;

use JSON qw/ from_json /;

use Test::TCP;
use WWW::Mechanize::PhantomJS;

use Dancer::Plugin::Test::Jasmine::Results;

Test::TCP::test_tcp(
    client => sub {
        my $port = shift;

        my $mech = WWW::Mechanize::PhantomJS->new;

        $mech->get("http://localhost:$port?test=verify_title");

        jasmine_results from_json
            $mech->eval_in_page('jasmine.getJSReportAsString()'; 
    },
    server => sub {
        my $port = shift;

        use Dancer;
        use MyApp;
        Dancer::Config->load;

        set( startup_info => 0,  port => $port );
        Dancer->dance;
    },
);

done_testing;

SEE ALSO

AUTHOR

Yanick Champoux yanick@babyl.dyndns.org endorse

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Yanick Champoux.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.