In my case, I started out with launching my server with plackup, but then I wanted a custom configuration and a fresh database, and I wanted to override how some functions return errors etc., and all of that becomes more cumbersome, together with the uncertainity whether I'm really connecting to the fresh instance and not a left-over instance from a previously interrupted test run.

But for a very simple start, this is an old version of the end-to-end test run setup I had:

package helper; use strict; use File::Path; use File::Temp 'tempdir'; use WWW::Mechanize::Chrome; sub spawn_app { my( $port ) = @_; my $h = helper::Child->new; $h->spawn_child( 'plackup', '-a', 'bin/app.pl', '-p', $port ); $h } my @cleanup_directories; END { File::Path::rmtree($_, 0) for @cleanup_directories; } sub spawn_chrome { my $tempdir = tempdir(); push @cleanup_directories, $tempdir; my $mech = WWW::Mechanize::Chrome->new( launch_exe => '...', data_directory => $tempdir, @_ ); } package helper::Child; use strict; sub new { my( $class, %options ) = @_; bless \%options => $class; } sub DESTROY { kill 'KILL', $_[0]->{pid}; wait; } sub spawn_child_win32 { my ( $self, @cmd ) = @_; system(1, @cmd) } sub spawn_child_posix { my ( $self, @cmd ) = @_; require POSIX; POSIX->import("setsid"); # daemonize defined(my $pid = fork()) || die "can't fork: $!"; if( $pid ) { # non-zero now means I am the parent $self->log('debug', "Spawned child as $pid"); return $pid; }; #chdir("/") || die "can't chdir to /: $!"; # We are the child, close about everything, then exec (setsid() != -1) || die "Can't start a new session: $!" +; open(STDERR, ">&STDOUT") || die "can't dup stdout: $!"; open(STDIN, "< /dev/null") || die "can't read /dev/null: $!"; open(STDOUT, "> /dev/null") || die "can't write to /dev/null: $!"; exec @cmd; } sub spawn_child { my ( $self, @cmd ) = @_; my ($pid); if( $^O =~ /mswin/i ) { $pid = $self->spawn_child_win32(@cmd) } else { $pid = $self->spawn_child_posix(@cmd) }; $self->{pid} = $pid; return $pid } 1;

Used as:

use lib './t'; use helper; my $port = 5099; my $server = helper::spawn_app( $port ); my $mech = helper::spawn_chrome( ); ...

In reply to Re^7: Testing javascript on Dancer2 psgi sites by Corion
in thread Testing javascript on Dancer2 psgi sites by nysus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.