Examining the script.aclo.us Unit Testing Implementation

Introduction


This article walks the brave reader through the guts of the unit testing code provided by script.aculo.us, (hereafter referred to simply “scriptaculous”, because that’s hard enough to type as it is) the JavaScript library that powers most of those nifty interactive and Ajaxy effects you’re enjoying on web sites these days.

This exegetical exercise sprang from my own personal desire to understand scriptaculous’ unit testing implementation in order to evaluate its potential for providing unit testing for a project of my own. The unittest.js file is examined, and in particular I take a very close look at Test.Unit.Runner. The details that follow would hopefully explain to interested parties how this code works, but it also, I think, serves as an elucidation of a lot of interesting topics in JavaScript: prototype-based object-orientation, constructors, JSON-like syntax, closures, and mixins, just to name a few.

And, also, the scriptaculous documentation is not quite complete, so this little exercise might provide some material for improvements in that regard.

As always, I would LOVE feedback. Please email me at mh (that’s.me) at this domain, and include something in the title like script.aculo.us, so I can easily pick you email out from spam. Although you never know, some spam camouflages itself eerily well.

So, if you’re ready to dive in…

Next: Tackling the Code

Or, you might want to skip right to the implementation of actual tests.

Unpacking multirember&co from TLS

The purpose of The Little Schemer, its authors profess, is to teach you to think recursively, and to do so without presenting too much math or too many computer science concepts. The book is a ball to read. However, from the perspective of this reader, who is fairly new to functional programming and totally new to Scheme, the book gets almost asymptotically more difficult and complicated towards the end of chapter 8, when we hit the function multirember&co. Looking around on the web, I noticed quite a few people had also hit this speed bump and were scratching their heads about how to go on. I think I can offer some assistance. So, as threatened yesterday, I now unveil my initial contribution to the wild world of Lisp, my explication of multirember&co and the concept of currying. Here’s hoping I don’t embarrass myself too much.

Continue reading

Seeking test frameworks for JavaScript

I’m doing a lot of work with JavaScript right now. I’ve been coding in sin, though: I haven’t done any regression testing. No unit tests, no functional tests. In part, I’ve just been lazy; but in my own defense, how do you unit test JavaScript?

Well, I’m thinking about collecting one of the most interesting pieces of code I’ve written for my latest project so that I can put in on SourceForge. I’ve never participated in Open Source development, but I’ve always wanted to. Releasing my code would be a small step into that world, and I’m eager to do it. But if I’m going to do that, a voice in my head insists, I can’t go releasing code that doesn’t have regression test coverage! So now, I have to figure out how to test in javascript.
Continue reading

What I’m Reading: Serious about C

So I’ve decided it’s time to learn C, for real. I used to know only enough to be dangerous. At the little startups I worked at, it was enough to know that a pointer was a reference to a memory address to impress people, but I couldn’t read real source code, and I didn’t know the kind of things Real Programmers know, like algorithms, linked lists, binary trees, etc. Discussions of those topics, Donald Knuth’s books notwithstanding, are in C, and my Java knowledge, such as it was, did not enable me to get past the first line that looked like this:

void
getfile(void (*fill)(char *, long), (*skip)(char *, long))


So I’ve been cozying up with The C Primer Plus, Fifth Edition, by Stephen Prata, and Code Reading, the Open Source Perspective by Diomidis Spinellis. The former is excellent, and the later… the jury’s still out.
Continue reading

Outstanding college radio for a college town

I have discovered perhaps my favorite thing so far about College Park, the university’s radio station WMUC. It’s a ten-watt station, and I’ve determined its signal doesn’t extend very far beyond the city and university limits. However, its truly excellent web site, wmucradio.com, is available to the broadband-enabled. You can listen in to the current show, but you can also access a whole week’s of archived shows in MP3 format. Most DJs also do a fine job of logging their playlists, so you can actually shop the archived shows to find something interesting. On top of that, WMUC organized an outstanding record swap at the student center a week ago. We had been jonesing to add vinyl to our collection, so I’m grateful.

Getting It Done, Part 2

I wrote a little while back about using Javascript and Ajax to build a dynamic and interactive interface for a site that would otherwise be flat HTML. My client is using a commercial ecommerce platform, ShopSite 8.1, which has a web-based admin interface for entering info about a product. The application then publishes summary and detail pages for the products. ShopSite uses an embedded database, but you can’t access it. You have to use it as a publish-once or “push” CMS. But my client wants beautiful and interactive pages, so my solution is to set up ShopSite to publish semantic HTML, much of it in div elements I’ve set to display:none, and use Javascript to parse the info in those divs and display it. Also, I can use Ajax to get more information form the server, especially information about artists, as that info isn’t stored in ShopSite but a separate MySQL database I set up.

I mentioned that I had to figure out how to do a few more things. Two of those challenges were:

  • Retrieve path information for files, e.g. images, related to specific products, using Ajax and JSON.
  • Store and retrieve large pieces of information, e.g. long book descriptions, or complicated info, like the captions for many photos associated with a product.

Here is a brief description of how I’ve done these things.
Continue reading