Integrating Perl and Javascript tests

Ovid on 2005-09-08T23:42:47

Want fame and fortune? Have more tuits than I do? Integrate Perl and Javascript tests. Here's how.

I'm writing Javascript tests for Bricolage 2.0 and realize I have a huge problem. The JS tests are run through a HTML document that passes a form object to a class:

JSAN.use('Test.More');
JSAN.includePath = ['../../../www/js'];
JSAN.use('Kinetic.Search');

var search_form = document.search_form;
var url         = new Kinetic.Search().buildURL(search_form);
var expected    = 'http://www.example.com/some/url';
is(url, expected, 'search_form should return the correct URL');

Now this is all well and good, but there's a serious problem here. The search forms are generated dynamically. I'm about to change how they work but I really don't want to have to keep remembering to update the form in my tests. It dawned on me that I could get around this by using HTTP::Server::Simple to generate forms and have the Javascript tests run against those. Thus, they're always running against real Perl code. I understand that Apache test may come close, but I don't know if it can run the Javascript tests.

Since I'd already be running a simple server, why not have the server run the real Perl test suite and pass those results to the Javascript Test.Builder? By running one server, I could run my Javascript and Perl tests at the same time. Cunning, eh?

Now if only I had the time to indulge in this ...

I'm sure you'd win many admirers if you have more time for this than I do :)

In fact, if you set it up so it can collect any valid TAP results, we could integrate just about any programming language tests with JavaScript. I don't know if this has ever been done before.


Inline::JavaScript

Dom2 on 2005-09-09T12:52:02

Could you use something like JavaScript or JavaScript::SpiderMonkey to get the JS tests run? Then you could pass in the form results directly.

-Dom

Re:Inline::JavaScript

Ovid on 2005-09-09T16:11:57

That has the downside of locking me into a particular JS engine. By doing it from the browser, I can use any browser I want and be sure that it's being tested appropriately.

Spidermonkey was briefly discussed with my boss yesterday. He pointed out that he doesn't know anyone who's successfully compiled it. That's a bit of an obstacle :)

Re:Inline::JavaScript

Dom2 on 2005-09-09T16:26:21

It's in the FreeBSD ports, how hard can it be? :)

-Dom

a bit late but...

da on 2005-11-15T15:30:16

http://www.livejournal.com/users/brad/2175150.html
Talks about testing javascript cross-platform via a perlbal server, and it seems related enough that you might be interested.