GithubHelp home page GithubHelp logo

mochista's Introduction

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

mochista's People

Contributors

alexdaube avatar graingert avatar laggingreflex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

graingert

mochista's Issues

Typescript support?

Hi, I'm just wondering does this work with typescript. I have tried and couldn't seem to get the watcher working with .ts or .tsx files. output is this, basically it doesn't seem to count my files as being changed and the coverage doesn't seem to be output. When i use nyc and mocha directly I can get the coverage for typescript and the watch works

image

This is my scripts

{
     "scripts": {
      "testit": "cross-env NODE_ENV=test mochista --test-files ./app/**/*.{ts,tsx} ./app/**/*.spec.{ts,tsx} -
          compilers ts:ts-node/register --require should --require ./test-setup.ts",
         "testit:watch": "npm run testit -- -w --all -vvv"
     }
}

Awesome module btw ๐Ÿ’ƒ

TypeError: Object.entries is not a function

Any ideas what could be causing this?
Using node v6.8.0

I'm getting this error after globally installing:

TypeError: Object.entries is not a function
    at exports.config (/usr/local/lib/node_modules/mochista/src/utils/logger/index.js:13:35)
    at createLogger (/usr/local/lib/node_modules/mochista/src/utils/logger/index.js:27:3)
    at Object.<anonymous> (/usr/local/lib/node_modules/mochista/src/utils/logger/index.js:39:16)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
Couldn't require "dist/bin", trying "src/bin"...
{ Error: Cannot find module './src/bin'
    at Function.Module._resolveFilename [as __resolveFilename] (module.js:469:15)
    at Function.requireUpPatch [as _resolveFilename] (/usr/local/lib/node_modules/mochista/node_modules/require-up/register.js:19:16)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/local/lib/node_modules/mochista/bin.js:14:22)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12) code: 'MODULE_NOT_FOUND' }
Couldn't require "src" either. Try compiling or use with 'babel-register' or `--harmony` flag

Cannot reconfigure logger (info/verbose/debug) in programmatic API

Currently it's impossible when using programmatic API to display info/verbose/etc level logs because with debug-logger they're configured at startup.

It might be possible with this: appscot/debug-logger#8 (edit: probably related debug-js/debug#370 (comment)) but it should probably configure logger in a way that's not tied to application startup in the first place, and instead can be initialized via a startup function. Perhaps taking logger from external sources which could solve laggingreflex/start-mochista#2

unmet dependency

I npm installed mochista 0.4.1 running on node 6.8.0 and npm 3.10.8 and received:

{ Error: Cannot find module 'ority'
    at Function.Module._resolveFilename [as __resolveFilename] (module.js:469:15)
    at Function.requireUpPatch [as _resolveFilename] (/Users/twoode/my_project/node_modules/require-up/register.js:19:16)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/twoode/my_project/node_modules/mochista/src/utils/pad.js:1:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at requireUp (/Users/twoode/my_project/node_modules/require-up/index.js:32:22)
    at Function.requireUpPatch [as _resolveFilename] (/Users/twoode/my_project/node_modules/require-up/register.js:13:18)
    at Function.Module._load (module.js:417:25) code: 'MODULE_NOT_FOUND' }

An npm install --save-dev ority fixes this

No coverage report generated

With this line as script mochista -w --live-server the coverage dir is created but empty (except a hidden .tmp dir). The live server installs with progress but does not seem to mount (on as SSH shell).

All settings of nyc and mocha?

Mochista currently doesn't use all of nyc/istanbul's and mocha's settings. I did initially aim to support them all so that it could be used as a replacement for both, but my own use cases were simple enough and I only implemented the settings I was using.

I hadn't even checked whether there would be clashes between their settings and mochista's own (if any). I also implemented a setting --all in mochista that had different purpose in nyc/mocha (issues pointed out in #2, fixed in 7f8900d a2db9f2).

So currently it doesn't support all nyc/mochista's settings, but I definitely plan to add them. PRs most welcome!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.