Last night, I got vows.js setup and running a dummy test. Tonight I would like to run it against the
player_from_querystring
fab.js app in my (fab) game.In my "just_playing" suite, I
require
the player_from_querystring
app:var vows = require('vows'),That does not work, though:
assert = require('assert');
var player_from_querystring = require('player_from_querystring').app;
var suite = vows.describe('just_playing');
cstrom@whitefall:~/repos/my_fab_game$ vowsChanging the
module:238
throw new Error("Cannot find module '" + request + "'");
^
Error: Cannot find module 'player_from_querystring'
at loadModule (module:238:15)
at require (module:364:12)
at Object.<anonymous> (/home/cstrom/repos/my_fab_game/test/just_playing.js:4:31)
at Module._compile (module:384:23)
at Module._loadScriptSync (module:393:16)
at Module.loadSync (module:296:10)
at loadModule (module:241:16)
at require (module:364:12)
at /home/cstrom/bin/vows:326:19
at Array.reduce (native)
require
statement to require('lib/player_from_querystring')
(the fab apps are in the lib
directory) does not help either. Now I get:cstrom@whitefall:~/repos/my_fab_game$ vowsSo you cannot require with relative paths in node.js / commonjs. You can muck with the require paths:
module:238
throw new Error("Cannot find module '" + request + "'");
^
Error: Cannot find module 'lib/player_from_querystring'
...
var vows = require('vows'),OK, so now I need to see if I can actually test that (fab) app that I required. I am keeping this as simple as possible for now. I add one batch of tests, with one topic and one actual test. I will worry about the terminology another day.
assert = require('assert');
require.paths.push("lib");
var player_from_querystring = require('player_from_querystring').app;
var suite = vows.describe('just_playing');
The actual test is from my existing test suite. It acts as a downstream (closer to the browser) fab app. It sends in a player query string and hopes to get a player object back:
var suite = vows.describe('just_playing').addBatch({The test ('is player') asserts that the ID of the player object is "foo", which was set in the query string.
'Body': {
topic: function() {
var head = {
url: { search : "?player=foo&x=1&y=2" },
headers: { cookie: null }
};
var player;
function downstream (obj) { if (obj) player = obj.body; }
var upstream_listener = player_from_querystring.call(downstream);
upstream_listener(head);
return player;
},
'is player': function (player) {
assert.equal (player.id, "foo");
}
}}).export(module);
Amazingly, this just works:
cstrom@whitefall:~/repos/my_fab_game$ vows --specI worked out most of the hard stuff when I first tested this app, but still, it is nice to know that I can get it converted so quickly to vows.js. It is even better to know that I can test my fab.js app with vows.js.
♢ just_playing
Body
✓ is player
✓ OK » 1 honored (0.083s)
Day #152
No comments:
Post a Comment