This kind of “I broke things, so now I will jiggle things randomly until they unbreak” is not acceptable.
Linus Torvalds
I have really been enjoying James Burke’s RequireJS library: http://blog.dohertycomputing.com/post/3466960658/requirejs and have recently applied it to a project at my day job. When it came to testing the application, I decided on QUnit for unit testing, and started poking into using it with RequireJS.
I was able to successfully run tests using the RequireJS approach, i.e., define a test module, with the code to be tested as explicit dependencies, and waiting to start the tests until the module and all its dependencies are loaded. Async behavior is handled via QUnit.stop()/start() as described in the QUnit API: http://docs.jquery.com/QUnit
define(
[
“my/moduletotest1”,
“my/moduletotest2”,
“my/moduletotest3”,
],
function (moduletotest1, moduletotest2, moduletotest3) {
return {
RunTests: function () {
test(“mod1test”, function () {
QUnit.stop();
moduletotest1.ajaxyMethod(arg, function(result) {
deepEqual(result, matchExpression);
QUnit.start();
});
});
test(“mod2test”, function () {
QUnit.stop();
moduletotest2.ajaxyMethod(arg, function(result) {
equal(result, matchExpression);
QUnit.start();
});
});
…
}
};
});
Then in the QUnit page script:
QUnit.config.autostart = false;
require(
[
“UnitTests/TestModule”,
],
function (testModule) {
QUnit.start();
testModule.RunTests();
}
);
Works like a charm!
Nice post by James Burke, author of RequireJS, (which I have fully embraced in my latest production app) on why the Asynchronous Module Definition (AMD) appears to be winning the JavaScript module wars. It’s a clear, concise, and cogent argument.
Node.js is an event-driven I/O framework for the V8 JavaScript engine on Unix-like platforms. It is intended for writing scalable network programs such as web servers. That’s right, a web server written in JavaScript! Server side JavaScript is a very hot topic right now, and the idea of an end-to-end solution with the same language on both the client and the server is a nice idea. While Node is really aimed more at high-performance, high-concurrency asynchronous server development, the “one language” idea is a novel bit of added sugar.
But what’s that, “Unix-like” platforms? What about Windows? Sure, you can run linux on a VM, or on a separate partition, but what if you want to run node directly within Windows?
Well, I came across a post by an Aussie named Tatham Oddie that addressed just that question, and now I have node running on my Windows 7 box!:
http://blog.tatham.oddie.com.au/2011/03/16/node-js-on-windows/
My first node server, displaying “hello world,” is up and running, and I’m juiced to start digging deeper and writing practical server implementations.
My short term goal is to build a simple end-to-end solution with all the pieces I’ve talked about recently: node as the server, RequireJS client-side modules, jQuery Templates, and jQuery DataLink
Stay tuned…