Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Testing javascript on Dancer2 psgi sites

by nysus (Parson)
on Jan 06, 2018 at 16:24 UTC ( [id://1206823]=note: print w/replies, xml ) Need Help??


in reply to Re: Testing javascript on Dancer2 psgi sites
in thread Testing javascript on Dancer2 psgi sites

How about Starman? I'm already using that.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

  • Comment on Re^2: Testing javascript on Dancer2 psgi sites

Replies are listed 'Best First'.
Re^3: Testing javascript on Dancer2 psgi sites
by Corion (Patriarch) on Jan 06, 2018 at 17:50 UTC

    I don't think my approach would work with Starman, since Starman uses fork, which means you will have more than one process running.

    Having more than one process running means that your test code will run more than once, which is at least not what I want when writing tests.

      You can tellstarman to not fork any children via max_servers=1 IIRC. (Might be 0, unsure. On mobile now...

      The way forward always starts with a minimal test.

      I'm still uncertain as to how I would do this. I tried this:

      my $test = Plack::Test->create($app, server => 'Twiggy', port => 5000);

      But I'm not sure how get WWW::Mechanize::Chome to make requests on the $test object. Can you give me a couple of hints?

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        This is the very rough cut of combining plackup (in the form of Plack::Runner) and Twiggy with WWW::Mechanize::Chrome. I intend to flesh this out a bit and package it into its own module, but for the time being it works well enough for me.

        Currently, this sets up / patches a Dancer application, but I imagine that converting this to use/support Dancer2 shouldn't be too hard, since all you need to get is $app somewhere, and most likely, Dancer2::Test has just enough code to give you the appropriate $app somewhere.

        #!perl -w use strict; use Twiggy::Server; use Dancer::Test; use File::Temp 'tempdir'; use WWW::Mechanize::Chrome; use Log::Log4perl qw(:easy); use Data::Dumper; use Test::More tests => 15; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ER +ROR #Log::Log4perl->easy_init($TRACE); # Set priority of root logger to E +RROR my $port = 5099; my $server = Twiggy::Server->new( host => '127.0.0.1', port => $port, ); $ENV{DANCER_APPHANDLER} = 'Dancer::Handler::PSGI'; my $handler = Dancer::Handler->get_handler(); Dancer::_load_app('App::mykeep'); my $app = $handler->psgi_app(); $server->register_service($app); # Fudge the config as appropriate for our test Dancer::config()->{mykeep}->{notes_dir} = tempdir( CLEANUP => 1, ); my @cleanup_directories; my $tempdir = tempdir( CLEANUP => 1 ); my $mech; $mech = WWW::Mechanize::Chrome->new( launch_exe => 'C:\\Users\\Corion\\Projekte\\WWW-Mechanize-Chrome\\ +chrome-versions\\chrome-65.0.3301.0\\chrome.exe', data_directory => $tempdir, #headless => 1, ); $mech->clear_js_errors(); my $console = $mech->add_listener('Runtime.consoleAPICalled', sub { diag join ", ", map { $_->{value} // $_->{description} } @{ $_[0]->{params}->{args} }; }); # run your tests here # ...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1206823]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-24 02:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found