jberger / Mojo-Phantom

PhantomJS client-side testing for Mojolicious apps
Other
13 stars 6 forks source link

exception / syntax error can cause test to hang forever #6

Open plicease opened 8 years ago

plicease commented 8 years ago

Consider:

use Mojolicious::Lite;

any '/' => 'main';

use Test::More;
use Test::Mojo::WithRoles qw/Phantom/;

my $t = Test::Mojo::WithRoles->new;

my $js = <<'JS';
  throw 'foo';
JS

$t->phantom_ok('main', $js);

done_testing;

__DATA__

@@ main.html.ep

<!DOCTYPE html>
<html>
  <head></head>
  <body>
  </body>
</html>

Because the exception is thrown before the code gets to the phantom.exit() the test hangs. Worse there isn't a diagnostic. Wrapping my code in an eval helps:

my $js = <<'JS';
  try {
    throw 'foo';
  } catch (e) {
    perl.fail('javascript exception: ' + e);
  }
JS

This might be a sane default (?), but does not help for a syntax error which also exhibits the same hang with no diagnostic.