Review of Using Node.js for UI Testing
My rating: 5 of 5 stars
The first good thing is that the author himself is a good guarantee, as Pedro Texeira is a renowned author already with his popular Node Tuts video tutorials. What we have here is a book about harnessing the power of Node.js but also of Zombie.js (general purpose web test suite) and Mocha to help testing UI, which means the reader gets introduced to several libraries / frameworks in one package.
The premise, as usual with other books from this publisher, is to keep it short and thorough (I hardly have so much time these days for the proverbial exceeding-the-800-page-count books of the past), building an app at the same time we build the test infrastructure around it- The app is trivial, couldn’t be otherwise given the length of the book, but it is a plus anyway since you get a first taste of node.js. Let’s see the chapters one by one.
Chapter 1 kicks off by reviewing Zombie.js as the preferred mechanism to test the UI in an easy way. The most interesting part is no doubt the one devoted to the internal workings of the library, more than the DOM or the “history of testing” sections, even if the explanation of testing (to a very basic level such as unit vs integration) can be useful for teams where a discipline of testing has never taken off and a lot of fud remains. In any case, I’d recommend further reading on the subject of headless testing, because the section may fall short for some.
Chapter 2 introduces the total newbie to installing Node and Flatiron, together with the ever useful npm package manager. The version shown in the screenshots in 0.8.7. When I am reading the book it is already 0.10.4. Also the installation of flatiron (an scaffolding fwk) and couchDB are explained.
Next, the reader is guided through the process of scaffolding the application with all the bits and pieces that speed up development (packages.json, couchDB twitter bootstrap, jquery), and then go on to actually building the app, beginning with the templates. It’s a lot of stuff, but Pedro manages to explain well. The only thing you could say is that the use of a scaffolding framework, as flatiron here, pretty much hides the proper node.js app and its structure.
Chapter 3 covers Zombie.js and Mocha, teaching us how to modify the app so that the headless browser harnesses the app, and how to structure the tests, although Mocha is explained more in-depth in Chapter 4 (“Understanding Mocha”), including a sort of introduction to the discipline of testing, its organization, hooks, assertions, etc.
The nicest about chapter 4 is that test building is carefully guided thru’, and we learn how to call pages, check their DOM structure, fill controls and press buttons with the framework objects. It’s all very very clear, even if testing a big non trivial app soon introduces some serious complexity. This can be quite useful for those who’ve never done much testing, either TDD or BDD.
Chapter 5 is a intro to headless browser library Zombie.js (which I personally had not used before). I think you get a pretty clear idea of the basic options you get, how to start testing and how to grow your tests more organically. It’s really the longest chapter and the more meaty one. Chapter 2 is actually longer but just because it covers node.js installation and so on. So you could say it is the core of the book.
Chapter 6, continues the testing, widening the scope to deal with interactions, that is testing that when select controls, radio buttons and so on, are selected or manipulated, the app reacts in the expected way.
Chapter 7 is devoted to giving the user some advice regarding debugging, including the Mocha reporters, and specific advice for debugging, running only some tests, such as dumping the contents of the Zombie browser object, etc.
We then move on to the last chapter, 8, Debugging Ajax with Zombie.js. The most interesting part here is how to set up testing for triggering events to test different integrations, for example an actual drag and drop. It’s the chapter that maybe feels a bit more rushed. Another example of a different ajax interaction would’ve been nice.
Some of the chapters run a bit short, but I believe that’s a bit of a trade off you need to make if you want to keep the book short, considering that in the end the book reads as a series of tutorials on different libraries with the common goal stated by the title. So, you learn the basics about Mocha, about Zombie.js, a very basic node.js app, etc.