Testing JavaScript from Perl

2009-11-06 − 🏷 javascript 🏷 perl 🏷 testing

If you want to write tests for your JavaScript code from Perl, Claes' module Test::JavaScript::More comes in handy. This module works by eval-ing everything from the use line as JavaScript. Of course, now you're mixing two languages in one file, which is not going to make any of your syntax validators happy. However, loading it like this will please both perl and jslint:

m| /* |; # Comment out JavaScript
use Test::JavaScript::More;
__END__ = '';  // It's is all JS from here. */
ok(1,'Success!');

One final note. I had some problems building the cpan module of JavaScript on OSX with SpiderMonkey from ports. If you have the same problem, get the latest and greatest version from GitHub, which fixes this issue.