Embed your unit tests in your source code.

Being able to add some tests for a component directly underneath its implementation feels oddly liberating. It's also pretty easy to set up. Suppose you have a a function countBears() with integrated test:

function countBears (animals) {
    return animals.filter(animal => animal === 'bear').length;
}

describe(countBears.name, function () {
    it('returns the amount of bears', function () {
        var animals = ['bear', 'fox', 'pig', 'bear'];
        require('assert').equal(countBears(animals), 2);
    });
});

Running the tests embedded in your source code is pretty easy. Just feed Mocha your source tree, and it will find the describe and it statements.

To generate production code with the describe and it statements removed, we can write some simple Sweet.js macros:

macro describe {
    rule { ($x:expr (,) ...) } => { }
}

macro it {
    rule { ($x:expr (,) ...) } => { }
}

export describe;
export it;

These macro's will match your describe and it statements and replace them with nothing. Sweet.js plugins are available for pretty much any build tool, so just include them in your chain and you're all set!