Last active
December 10, 2015 17:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
scripts: { | |
"test": "node ./run-tests" | |
//... | |
} | |
//... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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