Skip to content

Instantly share code, notes, and snippets.

@meisl
Last active December 10, 2015 17:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meisl/4470011 to your computer and use it in GitHub Desktop.
Save meisl/4470011 to your computer and use it in GitHub Desktop.
"just run my buster tests on `npm test`!" - "run-tests" should be in your project folder, as should "package.json". - "my-test1.js" assumed under test/ in your project folder
var buster = require("buster"); // on Windows you may need require("buster-node"); instead
var assert = buster.assert;
var refute = buster.refute;
buster.testCase("test case 1", {
setUp: function() {
// things to prepare before each test
},
tearDown: function() {
// things to clean up after each test
},
"a passing test": function() {
assert.equals(1, 1);
},
"a failing test": function() {
refute.equals(1,1);
},
"an async test, callback will be called eventually": function(testDone) {
var cp = require("child_process");
cp.exec("echo foo", function(err, stdout, stderr) {
assert(true); // your assertions here. with assert(true) we simply confirm that the callback was indeed called
testDone(); // MUST call this to tell buster that we're finally done with the test
})
},
"an async test, error from child_process.exec should be re-thrown": function(testDone) {
var cp = require("child_process");
var fnUnderTest = function(cmd) {
cp.exec(cmd, function(err, stdout, stderr) {
if (err)
throw err;
});
};
fnUnderTest("qumbl");
// Now HOW do I assert that a "No-such-command" is thrown eventually?
}
};
//...
scripts: {
"test": "node ./run-tests"
//...
}
//...
#!/usr/bin/env node
require("./test/my-test1.js");
require("./test/my-test2.js");
require("./test/my-test3.js");
//...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment