JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 43
  • Score
    100M100P100Q67288F
  • License MIT

Utility script to run tests and verify coverage threshold for stages files

Package Exports

  • testaged-coverage

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (testaged-coverage) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

testaged-coverage · Node.js CI · Node.js Package

Use this library to execute tests on your git staged files and verify they comply with the test coverage threshold.

You can install this dependency globally now (starting 1.3.3)

yarn add global testaged-coverage or

npm install testaged-coverage -g.

Before the tests are run, make sure you have set a Jest "coverageThreshold". You can learn how to configure it here.

// package.json
{
  ...
  "jest": {
    "coverageThreshold": {
      "global": {
        "branches": 80,
        "functions": 80,
        "lines": 80,
        "statements": 80
      }
    }
  }
}

How to use it

You need to stage your files first with git add.

In a pre-commit hook

You will need to have husky installed. In your package.json, add the script to run as a pre-commit hook.

// package.json
{
  "husky": {
    "hooks": {
      "pre-commit": "testaged-coverage && <you can include other scripts here (e.g. lint-staged)>"
    }
  },
}

Directly in command line

Just execute testaged-coverage

Starting 1.3.0 you can add a --basedir array of folders where to look for tests

testaged-coverage --basedir="src scripts folder1 folder2"

By default --basedir is folder src

Troubleshooting

This library assumes you have a script setup for tests in your package.json.

// package.json
{
  "scripts": {
    "test": "jest"
  },
}

If you are using versions 1.3.3 or lower, when running testaged-coverage, you will need to add the environment variable CI=true to your test script in your package.json in order to prevent the script from running in watch mode. This will no longer be necessary from versions 1.3.4 and on.