I've been banging my head at the wall since yesterday (only interrupted by a great Bruce Springsteen concert last night... ;-)
I am trying to add some JS testing to an existing (Rails) project. Basically the folder structure is this:
.
├── app
│ └── assets
│ └── javascripts
│ └── strftime.js
└── spec
├── buster.js
└── javascripts
└── strftime.test.js
In this very simple example I've taken the buster example from here https://gist.github.com/cjohansen/1904218 to be sure that everything worked before moving files around.
My buster.js looks like this:
var config = exports;
config["Server tests"] = {
// sources: ["../app/assets/javascripts/strftime.js"],
tests: ["javascripts/strftime.test.js"],
env: "node"
};
and I've tried modifying the first 5 lines of strftime.test.js to this:
if (typeof require == "function" && typeof module == "object") {
buster = require("buster");
require("../app/assets/javascripts/strftime.js");
}
Currently when I run buster test, I get this:
$ buster test
Failed requiring ./spec/javascripts/strftime.test.js: Cannot find module '../app/assets/javascripts/lib/strftime.js'
If I try to uncomment the sources line, buster test fails silently - even if I try to run it with high debug level.
I've zipped the entire example (2 KB) and put it here, if anyone would like try give it a try: http://gehling.dk/b2.zip
UPDATE: I've managed to require the js-file successfully by supplying the path relative to my test-js file:
if (typeof require == "function" && typeof module == "object") {
buster = require("buster");
require("../../app/assets/javascripts/strftime.js");
}
But I still have the problem with buster failing silently, if I add the sources parameter.
TIA
/ Carsten
In your zipped buster.js you reference a non-existent lib dir in your "sources" element:
var config = exports;
config["Server tests"] = {
// sources: ["../app/assets/javascripts/lib/strftime.js"],
tests: ["javascripts/strftime.test.js"],
env: "node"
};
You also reference the same lib directory in strftime.test.js.
By changing your buster.js to look like this:
var config = exports;
config["Server tests"] = {
rootPath: "../",
environment: "node",
sources: ["app/assets/javascripts/strftime.js"],
tests: ["spec/javascripts/strftime.test.js"],
};
And by changing the require statement in strftime.test.js to this:
require("../../app/assets/javascripts/strftime.js");
And running your tests with buster-test from within the spec dir, you'll get buster attempting to run some tests:
$ spec buster-test
Failure: Date strftime tests %j should return the day of the year
...
P.s., don't forget to link buster to your project with npm link buster.
Download the fixed files: http://speedyshare.com/FGvCe/b2.tar.gz