Mocha and Tape
I’ll even give you a seemingly accurate statistics of a Google Trends graph for Mocha vs Tape:
Tape is taking pride in doing things better than how Mocha is doing them, whether they are better code methodologies such as no global state shared between tests, and others such as providing a TAP output result which computers, parsers, bots, and some humans, can easily understand.
Tape was the conscience evolution choice after Mocha, but then came Ava.
Oh pretty Ava…
While I haven’t actually used Tape, just by comparing it with Ava it seems like Ava is Tape’s older brother. Or younger sister. oh well, you got the point, Ava is the new kid everyone wants to play with.
Highlights about Ava, yet there are probably more:
- Speed — Speed of tests running matters. It matters for CI and for you, because the time you wait for tests to finish you could have invested in writing and debugging code. Ava approaches this by spawning different Node.js processes to run your tests, and asynchronously running the tests inside them. This benefits from the side effect shared state between tests.
- Opinionated — Mocha doesn’t ship with an assertion library and is open for you to make use of anything you wish, may it be Chai, Should.js, or Node.js’s core Assert. Ava however, doesn’t leave room for confusion and provide it’s own assertion capabilities baked into Ava.
- Explicit — With Ava, all the library facilities you use are explicitly defined. Where in Mocha you have globals like describe or it, in Ava everything is declared, no globals.
- No Shared State — Ava makes use of Node.js’s asynchronous nature and runs tests in parallel, and also in dedicated Node.js processes. This means that making changes to files you require will not have an effect on other tests. Also, the use of beforeEach and friends in Mocha wouldn’t make sense anymore due to the parallelism of tests.
Disclaimer: Ava does support running tests serially through the test.serial() method or the — serial command argument for all tests, and it also has before/after hooks such as test.before(). Granted they exist for convenience and specific use cases, they aren’t encouraged.
Some other tools worth a mention if you’re in the test mood, each definitely deserve it’s own post.
Wallaby.js — A test runner that integrates with an IDE for a quick feedback loop on code coverage and tests.
There’s also a test library called Painless. Yes, I’m not kidding, there is definitely such a test library.
Would be interesting to see what yields next in 2017 (yes, that ES6 pun was intentional).