Convenient Test Executor for Node.js

6 May 2018

I was really surprised not finding a convenient test runner/executor in npm that can run test scripts in directory/directories recursively from the code. Also it would be nice to log how many tests are failed and passed, log stack traces of failed scripts, and log execution time. Moreover, I wanted to run scripts asynchronously. So, I decided that it's a great opportunity to create a such tool. I've called it test-executor, and it's iteresting that this name was available in npm. In this article I'll explain how this library works and how to use it.

This library is based on Async Tree Pattern. And that's how you can use it:

const { ExecutedTests } = require('test-executor')

new ExecutedTests(
  './test/test.js', './test/dir1', './test/dir2'

Or, if you want to run everything in test directory, you can just type

new ExecutedTests('./test').call()

You can specify files or/and directories in arguments. In case of directories, it runs them recursively. The main feature of this library is that it runs tests asynchronously. It forces you to write tests independetly, thereby they are more stable and maintainable.

Here is an example of output (case when one of the tests fail): output


P.S. I know that there are test runners like Mocha, Jest, Ava, and so on. But, in my opinion, this library is much more pleasant to use.

Reddit Comments / HN Comments