Buster.JS

Fremtiden innen JavaScript-testing

August Lilleaas

+

Christian Johansen

var config = module.exports;

config["App"] = {
    sources: [
        "../lib/app.js",
        "../lib/**/*.js"
    ],
    tests: [
        "*_test.js"
    ]
}
buster.testCase("My example tests", {
    "test assertions": function () {
        buster.assert(true);
    },

    "test refute": function () {
        buster.refute(false);
    },

    "test asynchronous": function (done) {
        setTimeout(function () {
            buster.assert(true);
            done();
        }, 100);
    }
});
~/myprojbuster static
Starting server on http://localhost:8282/

^C
~/myprojbuster static --config test/buster.js
Starting server on http://localhost:8282/
~/myprojbuster static ~/Desktop/test-out
Files written to /home/augustl/Desktop/test-out
To run tests, open this file in a browser:
    file:///home/augustl/Desktop/test-out/index.html
~buster server
buster-server running on http://localhost:1111
~/myprojbuster test
Chrome 14.0.835.202 Linux: ...
Firefox 8.0 Linux:         ...
2 test cases, 6 tests, 6 assertions, 0 failures, 0 errors, 0 timeouts
~/myprojbuster test --reporter bddConsole
Firefox 8.0 Linux
  ✓ My example tests test assertions
  ✓ My example tests test refute
  ✓ My example tests test asynchronous
1 test case, 3 tests, 3 assertions, 0 failures, 0 errors, 0 timeouts
Finished in 0.106s
~/myprojbuster test --reporter xml
<?xml version="1.0" encoding="UTF-8" ?>
<testsuites>
    <testsuite errors="0" tests="3" time="0" failures="0" name="Firefox 8.0 Linux">
        <testcase time="0.105" classname="Firefox 8.0 Linux.My example tests" name="test assertions"/>
        <testcase time="0" classname="Firefox 8.0 Linux.My example tests" name="test refute"/>
        <testcase time="0" classname="Firefox 8.0 Linux.My example tests" name="test asynchronous"/>
    </testsuite>
</testsuites>
var config = module.exports;

config["App"] = {
    sources: ["../lib/**/*.js"],
    tests: ["*_test.js"],
    resources: {
        "/app": "http://10.0.0.1:3000"
    }
}
var config = module.exports;

config["App"] = {
    sources: ["../lib/**/*.js"],
    tests: ["*_test.js"],
    testbed: "my-strict.html"
}
buster.testCase("My example tests", {
    "test not asynchronous": function () {
        buster.assert(true);
    },

    "test asynchronous": function (done) {
        setTimeout(function () {
            buster.assert(true);
            done();
        }, 100);
    }
});
buster.testCase("My example tests", {
    "test assertions": function () {
        buster.assert(true);
    },

    "a context": {
        "test some more": function () {
             buster.assert(true);
        }
    }
});
"test assertions": function () {
    buster.assert(true);
    buster.assert.equals("foo", "foo");
    buster.assert.match(someObj, {foo: "bar"});
    buster.assert.same(a, b);
    buster.assert.isNull(c);
},

"test assertions": function () {
    buster.refute(false);
    buster.refute.equals("foo", "bar");
    buster.refute.match(someObj, {foo: "bar"});
    buster.refute.same(a, b);
    buster.refute.isNull(c);
}
buster.spec.expose(); // Make functions global

var spec = describe("Bowling kata", function () {
    before(function () {
        this.game = new BowlingGame();

        this.rollMany = function (rolls, pins) {
            for (var i = 0; i < rolls; ++i) {
                this.game.roll(pins);
            }
        };
    });

    should("yield 0 in score for gutter game", function () {
        this.rollMany(20, 0);
        buster.assert.equals(0, this.game.score());
    });
});
var buster = require("buster");

buster.testCase("My example tests", {
    "test assertions": function () {
        buster.assert(true);
    },

    ....
});
var config = module.exports;

config["App"] = {
    env: "node",
    tests: ["*_test.js"]
}
var config = module.exports;

config["Node tests"] = {
    env: "node",
    tests: ["*_test.js"]
}

config["Browser tests"] = {
    env: "browser",
    sources: [
        "../lib/mylib.js",
        "../lib/**/*.js"
    ],
    tests: ["*_test.js"]
}
~buster server
buster-server running on http://localhost:1111
^C
~
~/myprojbuster test
No server detected at localhost:1111, running headless.

PhantomJS: ...
1 test case, 3 tests, 3 assertions, 0 failures, 0 errors, 0 timeouts
~/myprojbuster test
ENOENT, No such file or directory
  '/home/augustl/myproj/doesnotexist.js'
~/myprojjava -jar /home/augustl/bin/jar/JsTestDriver.jar --config test/jsTestDriver.conf --tests all
java.lang.IllegalArgumentException: The patterns/paths /home/augustl/myproj/test (/home/augustl/myproj/test)  used in the configuration file didn't match any file, the files patterns/paths need to be relative /home/augustl/myproj/test
	at com.google.jstestdriver.PathResolver.expandGlob(PathResolver.java:170)
	at com.google.jstestdriver.PathResolver.resolve(PathResolver.java:109)
	at com.google.jstestdriver.config.ParsedConfiguration.resolvePaths(ParsedConfiguration.java:98)
	at com.google.jstestdriver.config.Initializer.initialize(Initializer.java:84)
	at com.google.jstestdriver.JsTestDriver.runConfigurationWithFlags(JsTestDriver.java:259)
	at com.google.jstestdriver.JsTestDriver.runConfiguration(JsTestDriver.java:211)
	at com.google.jstestdriver.JsTestDriver.main(JsTestDriver.java:144)
Unexpected Runner Condition: The patterns/paths /home/augustl/myproj/test (/home/augustl/myproj/test)  used in the configuration file didn't match any file, the files patterns/paths need to be relative /home/augustl/myproj/test
 Use --runnerMode DEBUG for more information.

Buster.JS er
fremtiden innen JavaScript-testing

Masse kule og unike features

Alt på ett sted

Startet: oktober 2010

Annonsert: mai 2011

Lansert beta: ???

http://busterjs.org

Buster.JS