mocha-decaf
Run mocha tests in dry-run mode, it's like mocha but without caffeine
Install
Using npm
$ npm i mocha-decafAlternatively using yarn
$ yarn add mocha-decafUsage
You can use
mocha-decafto run your tests the same way you usemocha$ mocha-decaf --recursiveFor a complete list of command line arguments and options check Mocha's Documentation
You can also run and list the tests programmatically
const { isJSFile, listFiles, listExecutedTests, runMocha } = require('mocha-decaf') // list the js files under the test directory const testFiles = listFiles('./test').filter(isJSFile) // run the tests with the base mocha reporter const runner = runMocha(testFiles, { reporter: 'base' }) // list the tests executed const tests = listExecutedTests(runner) console.log(tests.join('\n'))For a complete list of the available functions check the API documentation
The above code is exported with the following command
$ mocha-list ./test
How is this package useful ?
You can use this package to list all the tests that should be run without actually running them to show what your tests are covering to stakeholders
You can also do all sorts of stuff before you actually run your tests using
mochalike partitioning the tests to run them in batches on different machines in parallel, checkout Mocha's test filters
Notes
- This package is only useful till
mochaimplements this functionality, however it doesn't seem this is going to happen in the near future since a PR was submitted 6 years ago and rejected.
How it works
The command simply patches Mocha's test runner to pass any test then calls mocha to run all tests.
Starting from v0.2.0 it also patches before, beforeEach, after and afterEach
Caveats
- Some
mochaarguments won't behave identically when used withmocha-decafmost notably--forbid-onlybecause it should make the tests marked as.onlyfail however all tests will pass.