Home

Awesome

flow-coverage-report

Greenkeeper badge

Build Status

flow-coverage-report is a node command line tool to help projects which are using flow types in their JavaScript code to keep track and visualize the coverage of the flow types checks.

Screenshot flow coverage report summary in the console

Screenshot flow coverage report summary

Screenshot flow coverage report sourcefile

How to generate flow coverage reports for your project

Install the command line tool (globally or as a dev dependency of your project)

$ npm install -g flow-coverage-report

or

$ npm install --save-dev flow-coverage-report

Run the flow reporter (-i configures the include globs, -x the exclude patterns, --threshold to configure a minimum coverage below which the build should fail, which defaults to 80%, and -t the report types enabled):

flow-coverage-report -i 'src/**/*.js' -i 'src/**/*.jsx' -x 'src/test/**' -t html -t json -t text --threshold 90

If the flow executable is not in your PATH, you can specified it using the -f option:

flow-coverage-report -f /path/to/flow ...

To customize the output dir (which defaults to flow-coverage/) you can use the -o option. Though by default the output type is text meaning that it ouputs to the console. Use -o in conjunction with -t to save your desired format:

flow-coverage-report -o my-custom-flow-coverage-dir/

To customize the type you can use -t options:

flow-coverage-report -t html

Load default options from a JSON config file

The --config flag allows specifying a path to a config file. The config file is a JSON file with the following structure:

{
  "concurrentFiles": 1,
  "globExcludePatterns": ["node_modules/**"],
  "flowCommandPath": "path/to/flow/bin",
  "globIncludePatterns": ["src/**/*.js"],
  "outputDir": "path/to/output",
  "projectDir": "path/to/project",
  "threshold": 90,
  "reportTypes": "text"
}

type can be one of "text", "html", or "json". The default is "text".

Load default options from package.json

For an npm package, the default options can also be configured by including them in a "flow-coverage-report" package.json property property:

{
  "name": "my-npm-package",
  "version": "1.0.1",
  "scripts": {
    "flow-coverage": "flow-coverage-report",
    ...
  },
  ...
  "flow-coverage-report": {
    "globIncludePatterns": [
      "src/lib/**/*.js",
      "src/lib/**/*.jsx"
    ],
    "reportTypes": [
      "text",
      "html",
      "json"
    ]
  }
}

Background

As a gradual typing system for JavaScript, flow will help you to statically checks parts of your JavaScript code by:

Unfortunately, even with a good amount of powerful inferencing strategies, sometimes flow is not able to inference the types in some chunks of our code.

That's usually the source of a "Meh!" moment, and we blame flow for not being able to catch some issue that we thought it would catch statically.

Fortunately, flow has a coverage command which can give us a quantitative info of the flow types coverage, and optionally a color-based visualization of the parts of the source file that are not covered, for a single file.

How to generate this quantitative info and this very useful visualization of the uncoverage parts of our sources for our entire project?

You have just found it ;-)

Changelog

0.8.0

Fixes:

0.7.0

⚠ BREAKING CHANGES ⚠

Fixes:

0.6.2

0.6.1

Fixes:

0.6.0

Bug Fixes:

Features:

This new release fixes the issues with the new flow annotations (e.g. strict and strict-local) and introduces two new command line options:

Thanks to Ville Saukkonen and Ben Styles for contributing the new --exclude-non-flow and --percent-deciments options, and Xandor Schiefer for adding support to the new flow annotations.

0.5.0

Features:

The new badge reporter is implicitly executed when the html report is enabled and it generates two badges: 'flow-badge.svg' is a badge related to the flow validation check, 'flow-coverage-badge.svg' is a badge related to the flow coverage level reached by the project.

The new --strict-coverage option enables a more strict coverage reporting where only the flow annotated files are considered as covered (while all the non annotated files and the "@flow weak" annotated ones are considered as fully uncovered).

Thanks to Rúnar Berg Baugsson Sigríðarson for contributing the new badge reporter, and to Desmond Brand and Matt Sprague for contributing the new --strict-coverage option.

0.4.1

Bug Fixes:

Thanks to Ryan Albrecht and Karolis Grinkevičius for their help on this bugfix release.

0.4.0

Features:

Bug Fixes:

Thanks to Ryan Albrecht, Boris Egorov, Julien Wajsberg for their help on this new release.

0.3.0

Introduces the new command line options:

flow-coverage-report v0.3.0 loads the configuration automatically from the flow-coverage-report section of the target project package.json (or from a .flow-coverage-report.json file in the project dir), which is going to help to reduce the number of command line options that have to be explicitly passed on the command line.

In this version, the flow-coverage-report npm package is also switching to a MIT license.

Features:

Bug Fixes:

Thanks to Ryan Albrecht, Jason Laster, Guillaume Claret and Steven Luscher for their help on this new release.

0.2.0

Introduces the new command line options:

flow-coverage-report v0.2.0 also introduces some fixes needed to be able to generate flow coverage reports on larger projects (and projects with flow issues) and new command line options:

Thanks to Ilia Saulenko, Ryan Albrecht and Jason Laster for their help on this new release.

0.1.0

Initial prototype release:

Thanks to Kumar McMillan and Andy MacKay for their advice and support, this project and its github repo wouldn't exist without you.