Skip to content

laggingreflex/mochista

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mochista

npm

Like* Mocha + Istanbul c8* in a single process.

Mochista uses Mocha and Istanbul c8's programmatic API to run both in a single process* yielding fastest test results and coverage reports.

Its --watch feature runs modified tests and generates coverage using cache for unmodified files instantly:

Protip: Use --coverage-server flag to run live-server (via npx) on the coverage dir to view live changes to coverage reports.

Update: Major Rewrite

Uses c8

After recently discovering c8 I decided to rewrite this to use that instead of Istanbul. But c8 still uses Istanbul under the hood to generate reports and such, so the overall outcome of this change should be more or less the same as before.

Also running everything in single-process is also no longer the case, since c8 uses Node's built in coverage functionality which only outputs coverage data once the Node processes has exited, tests now need to be run in a separate (forked) process. There doesn't seem to be too much of a noticeable performance hit, since forked processes are still quicker than separate shell commands.

Not all features of Mocha and Istanbul supported

Incorporating all functionalities of both Mocha and Istanbul is no longer the intent of this project. Earlier this project may have claimed to be a drop-in replacement for both, but that is no longer the case (in hindsight it wasn't a wise decision to begin with, since there were/would've been a lot of flag/features collisions). It'll however still try to support some of the most common features (bail, fgrep) with direct flags or --mocha-xxx prefix.

Node v10.10

Another thing this rewrite did was to massively simplify the code (1.3k->300 LOC), and some of the features (Async Iteration) are heavily reliant on latest NodeJS (v10).

I don't currently plan to use babel to transpile-down.

Also c8 uses Node's built in coverage functionality which requires Node >= v10.10.

Features

  • Run tests and generate coverage reports

  • Like mocha --watch but with Istanbul coverage reports.

Note: Following features have been removed since the update.

  • Run only modified tests. It's far simpler (and not that slow) to just re-run everything.

  • Instrumentation caching on disk and memory for fastest coverage report generation and re-generation. Not needed anymore.

  • Supports mocha.opts with extra features. See above. It does support .env file (via dotenv) and all can take all command-line flags from it (via yargs' .env feature)

  • Built in support for ES6/ES2015+ by using coverage source-maps. See below

Install

npm i -g mochista

Usage

mochista [options]
Options:
  --help             Show help  [boolean]
  --version          Show version number  [boolean]
  --cwd              Current dir  [string]
  --testFiles, -t    Files to test (anymatch)  [array] [default: ["*test*/**","**/*.test.*","**/test.*"]]
  --sourceFiles, -s  Source files (for coverage) (anymatch)  [array] [default: ["."]]
  --exclude          Files to exclude (anymatch)  [array] [default: [".*","node_modules","coverage"]]
  --gitignore        Files to exclude based on .gitignore  [string] [default: [".gitignore","~/.gitignore"]]
  --extensions       Extensions to monitor (all other files ignored)  [array] [default: [".js"]]
  --watch, -w        Watch for file changes and re-run. `--watch=i` to only re-run on pressing Enter
  --parallel         Use mocha-parallel-tests to run each of your test files in a separate process
  --coverage         Collect coverage (use --no-coverage to disable)  [boolean] [default: true]
  --coverageDir      Directory to output coverage and reports  [string] [default: "./coverage"]
  --coverageServer   Run live-server (via npx) on coverage dir  [boolean]
  --reporter         Mocha reporter  [string] [default: "spec"]
  --report           Istanbul reporters  [array] [default: ["text","lcov","html"]]
  --require, -r      Require the given module  [array] [default: []]
  --all, -a          Instrument all files  [boolean]
  --mocha-xxx        All mocha-related options, like --mocha-fgrep etc
  --config           JS/JSON config file path

Options can be provided in --camelCase, --hyphen-case or set as environment variables (which can also be read from .env file) in UPPER_SNAKE_CASE=.

Other than explicitly setting a boolean to =false, you can also use the --no- prefix, like --no-coverage

Issues

Transpilers

Personally not a huge fan of transpilers (babel, typescript) so they've neither been tested nor support for them is provided currently.

Libraries used

About

Mocha + c8 in a single process

Resources

Stars

Watchers

Forks

Packages

No packages published