nysus has asked for the wisdom of the Perl Monks concerning the following question:

I've been reading up on various modules for test the output from a Dancer2 website, specifically Plack::Test. This module makes it exceedingly easy to start up a standalone website on the fly. I also found this module, Test::WWW::Mechanize::PSGI which looks great. However, there is no way (that I can see, at least) that either of these two modules can be used to test javascript that fiddles with the DOM on the page. So the best alternate route, at least from what I can see, is to set up a site on a server manually and test it with WWW::Mechanize::Chrome or maybe WWW::Scripter.

So I'm wondering if there is some solution out there that will let me easily run tests on a site with javascript on via psgi. Thanks.

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

Replies are listed 'Best First'.
Re: Testing javascript on Dancer2 psgi sites
by 1nickt (Canon) on Jan 06, 2018 at 15:55 UTC

    WWW::Mechanize does not handle JavaScript. Other modules do, e.g. WWW::Mechanize::Firefox. Personally I use Selenium::Remote::Driver with Selenium and headless Firefox.

    Otherwise, you can test your JavaScript directly with JavaScript testing framework such as Cucumber, Jest, etc.

    Hope this helps!


    The way forward always starts with a minimal test.
Re: Testing javascript on Dancer2 psgi sites
by Corion (Patriarch) on Jan 06, 2018 at 16:13 UTC

    You can run any PSGI app together with your WWW::Mechanize::Chrome test script in the same process if you use a webserver like Twiggy. That allows you to conveniently test your Javascript without launching a separate process for your web application.

      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

        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.