Skip to content

Instantly share code, notes, and snippets.

View cjohansen's full-sized avatar

Christian Johansen cjohansen

View GitHub Profile
@cjohansen
cjohansen / gist:1005997
Created June 3, 2011 07:09
Sample sinon-nodeunit test
require("sinon-nodeunit");
exports.testSomething = function (test) {
test.expect(1);
test.ok(true, "this assertion should pass");
test.done();
};
exports.testSomethingElse = function (test) {
test.ok(false, "this assertion should fail");
@cjohansen
cjohansen / gist:1144199
Created August 13, 2011 19:56
Put all JavaScript test files in buster-mode minor mode
(add-to-list 'load-path "/path/to/buster-mode")
(autoload 'buster-mode "buster-mode")
(add-hook 'find-file-hook
(lambda ()
(let* ((file (buffer-file-name))
(len (length file)))
(if (equal (substring file (- len 7) len) "test.js") (buster-mode)))))
@cjohansen
cjohansen / gist:1486702
Created December 16, 2011 16:23
Asynchronous Buster.JS tests
// Oops: Defaut test runner timeout is 250ms
buster.testCase("Async stuff", {
"does things asynchonously": function (done) {
setTimeout(function () {
assert(true);
done();
}, 100);
},
// Plugin
module.exports = {
configure: function (config) {
config.on("load:sources", function (sources) {});
config.on("load:resources", function (resourceSet, rootPath) {});
},
run: function (testRunner) {},
// ...
module.exports = {
configure: function(conf) {
var testsToLoad = [];
conf.options.autoRun = false;
conf.on("load:tests", function(tests, root) {
while(tests.length > 0) {testsToLoad.unshift(tests.pop())}
});
conf.on("load:resources", function(rs) {
var testsStr = testsToLoad.map(function (t) { return "'" + t + "'"; }).join(", ");
var res = rs.addResource("/_buster-load-all.js", {
// Original
it("fetches a resource", function() {
this.jQueryGet = this.sandbox.stub(jQuery, "get"),
this.response = null
this.jQueryGet.callsArgWith(1, "OK")
this.object.fetch("/foo", function(r) { this.response = r }, this)
waitsFor(function() { return this.response })
runs(function() {
;; Scenario: Mark word just behind point
;; Given there is no region selected
;; When I insert "This is some text"
;; And I go to point "13"
;; And I expand the region
;; Then the region should be "some"
(bdd/scenario "Mark word just behind point"
(bdd/insert "This is some text")
(bdd/goto 13)
config.on("load:tests", function (resourceSet) {
resourceSet.addProcessor(function (resource, content) {
var parsed = parseScript(content);
// Loop AST, extract /*:DOC */ comments, convert them
// Make sure to maintain line-numbers in the output
return modifiedScriptContents;
});
});
@cjohansen
cjohansen / buster-api.js
Created February 19, 2012 13:07
A dump of available functions in Buster.JS. Useful for helping various editors and IDE's build up their autocompletion-fu when writing tests with Buster.JS
var buster = {
assert: function assert(actual, message) {},
assertions: {
add: function (name, options) {},
addListener: function addListener(event, listener, thisObject) {},
assert: function assert(actual, message) {},
bind: function (object, events) {},
captureException: function captureException(callback) {},
contexts: { },
create: function () {},
@cjohansen
cjohansen / buster.js
Created February 24, 2012 22:30
A simple JavaScript project tested with Buster.JS
var config = exports; // Vanity
config["Browser tests"] = {
environment: "browser",
sources: ["strftime.js"],
tests: ["strftime-test.js"]
};
config["Server tests"] = {
extends: "Browser tests",