Sunday, May 23, 2010

I Can't Test Fab.js

‹prev | My Chain | next›

Up tonight, I would like to start working through testing my (fab) game. So far, I have not done any, and feel like I'm pushing my luck with keeping this together. I know that Cucumber now runs (at least as a proof of concept) under the v8 javascript engine. Before I go there, I would like to be able to at least run the fab.js test suite. Or at lest one test.

Way back, a reader provided a clue as to how to run a single test. This is a good thing because none of the built-in test like scripts seem to do anything:
cstrom@whitefall:~/repos/fab$ node utils/test.js
<no output>
cstrom@whitefall:~/repos/fab$ node utils/build.js
<no output>
cstrom@whitefall:~/repos/fab$ node builds/all.js
<no output>
What's worse is that the "core" test fails completely:
cstrom@whitefall:~/repos/fab$ node builds/core.js 
Error: Cannot find module '/home/cstrom/repos/fab/apps/fab.Function'
at loadModule (node.js:492:15)
at require (node.js:618:12)
at /home/cstrom/repos/fab/utils/build.js:10:15
at Array.forEach (native)
at /home/cstrom/repos/fab/utils/build.js:6:8
at Object.<anonymous> (/home/cstrom/repos/fab/builds/core.js:12:41)
at Module._compile (node.js:639:23)
at node.js:667:20
at fs:52:23
at node.js:748:9

I can get that "working", in the sense that it does not crash, by adding a "defaults" object namespace to some of the apps in core.js:
var apps = exports.apps = [
, "fab.body"
, "fab.defaults"
, "fab.defaults.Function"
, "fab.identity"
, "fab.defaults.Number"
, "fab.path"
, "fab.defaults.RegExp"
, "fab.status"
]; = require( "../utils/build" )( apps ).app;
But that does me little good as running that file with node now returns right away without any output as well.

Let's see if I can get a single test to run. Thanks to the comment from istruble, I know that I can create a my_test.js file in the root directory of the fab.js source with contents like:
var test = require("./utils/test"),
target_module = require('./apps/fab.status');
And indeed that does work:
cstrom@whitefall:~/repos/fab$ node my_test.js
Running 3 tests...
statusReturnsUnaryApp: true
statusRespondsWithCorrectPayload: true
statusClosesConnection: true
Done. 3 passed, 0 failed.
I fiddle with that for a bit longer to see if I can get it to load in more tests automatically, but the overall approach feels very manual. I am forced to call it a night at this point. I think tomorrow I will move on to try Cucumber.

Day #112

No comments:

Post a Comment