busterjs / buster

Abandoned - A powerful suite of automated test tools for JavaScript.
http://docs.busterjs.org
Other
448 stars 37 forks source link

support other assertion libraries #137

Closed flosse closed 12 years ago

flosse commented 12 years ago

It would be great if you can use another libs like chai.js or should.js

cjohansen commented 12 years ago

If they throw AssertionErrors they can be thrown right in. Otherwise they need a little bit of glue, we already have several hooks available. Want to take a stab at integrating them?

cjohansen commented 12 years ago

Both of these throw AssertionErrors, so there's nothing to do to support them. Just add them as libraries in your project and use at will.

flosse commented 12 years ago

There is still WARNING: No assertions!. Where is my mistake?

buster  = require "buster"
app     = require "../src/myApp"
chai    = require('chai').should()

buster.testCase 'does chai work?',

  'hello chai': ->
    "a".should.equal "b"
Failure: does chai work? hello chai
    expected 'a' to equal 'b'

1 test case, 1 test, 0 assertions, 1 failure, 0 errors, 0 timeouts
WARNING: No assertions!

edit: same problem with should.js

cjohansen commented 12 years ago

Ah, so Buster will catch the errors, but is never notified of success. That requires a (very small) extension to do. If you don't want to do it, you can silence the error:

buster.testRunner.failOnNoAssertions = false;

However, by doing that you're opting out of potentially very useful information. A better approach would be to create a small buster-chai extension that pings buster on assertion success.

flosse commented 12 years ago

Are there any docs/tutorials/examples how to create buster extensions? Or could you give me some hints where to start studying the buster code?

magnars commented 12 years ago

buster-chai should be a subset of buster-jstestdriver code. Check that out first. :-) https://github.com/busterjs/buster-jstestdriver

flosse commented 12 years ago

@magnars: thx, I'll have look at it and hopefully I'll be able to write the extension.

magnars commented 12 years ago

@flosse Don't be discouraged by the size of buster-jstestdriver, it does quite a bit more than you need to do. I'm sure @cjohansen can give you a more precise starting point.

cjohansen commented 12 years ago

Actually, you don't need an extension for this, you only need a wrapper module. This is how buster-assertions integrates with the runner:

    var buster = require("buster-test");
    buster.assertions = require("buster-assertions");
    var assertions = 0;
    var count = function () { assertions += 1; };
    buster.assertions.on("pass", count);
    buster.assertions.on("failure", count);
    buster.testRunner.assertionCount = function () {
        return assertions;
    };

Looking at this I'm not very impressed, to be honest. Should probably just be something like buster.testRunner.countAssertion().

flosse commented 11 years ago

Hey buster.js team! Unfortunately I still couldn't find some time to implement an extension. Are the any new changes so far that makes it possible to use chai.js easily?