npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

typhonjs-npm-scripts-test-mocha

v0.5.4

Published

Provides NPM scripts for testing projects using Istanbul and Mocha for all TyphonJS NPM modules and beyond.

Downloads

49

Readme

typhonjs-npm-scripts-test-mocha

NPM Code Style License Gitter

Build Status Dependency Status

Requirements: Node v5+ / NPM 3+

Provides NPM scripts for testing with Mocha / Chai, generating code coverage with Istanbul and uploading results to Codecov when running continuous integration on Travis CI for all TyphonJS NPM modules and beyond. Linting support is also enabled via ESLint.

This NPM module uses entries defined in the test entry located in .npmscriptrc or .npmscriptrc.js in the root path of a project. This module works for both ES5 and ES6+ testing, but please note the usage instructions below for ES6 testing.

For the latest significant changes please see the CHANGELOG.

  • IMPORTANT (breaking change): The codecov.io NPM module has been deprecated and also contains potential vulnerabilities and has been removed in favor of the official codecov NPM module. You will need to modify .npmscriptrc and replace "travis": { "report": "cat ./coverage/lcov.info | ./node_modules/codecov.io/bin/codecov.io.js" }, with "travis": { "report": "./node_modules/.bin/codecov" },. Apologies for the inconvencience. See CHANGELOG for more details.

  • IMPORTANT (breaking change): In release 0.5.0 release snyk has been removed.

For a comprehensive ES6 build / testing / publishing NPM module please see typhonjs-npm-build-test as it combines this module for testing along with transpiling ES6 sources with Babel, pre-publish script detection, ESDoc dependencies and an Istanbul instrumentation hook for JSPM / SystemJS tests. For a full listing of all TyphonJS NPM script modules available please see typhonjs-node-npm-scripts organization on GitHub.

There are three testing scripts provided by this module:

mocha.js just runs Mocha tests.

Both mocha-istanbul.js and mocha-istanbul-report.js execute Mocha tests and Istanbul. Also an additional report command in .npmscriptrc is executed afterward if defined which is useful when running on Travis CI to upload results to Codecov.

The main difference between mocha-istanbul.js and mocha-istanbul-report.js is that istanbul report is automatically run after the initial istanbul command from .npmscriptrc is executed. This is necessary for instance when instrumenting JSPM / SystemJS tests.


To configure the test scripts provide this entry in package.json scripts entry:

  "devDependencies": {
    "typhonjs-npm-scripts-test-mocha": "^0.5.0"
  },
  "scripts": {
    "test": "babel-node ./node_modules/typhonjs-npm-scripts-test-mocha/scripts/mocha.js",
    "test-coverage": "babel-node ./node_modules/typhonjs-npm-scripts-test-mocha/scripts/mocha-istanbul.js"
  },

Please note the usage of babel-node to invoke the test scripts. If you are using ES6 for tests and sources and have Babel or typhonjs-npm-scripts-build-babel installed use babel-node instead of node.

.npmscriptrc must be defined in the root path and contain a JSON formatted object hash test hash with the following options:

(string)          report - An optional command to execute that may upload results to Codecov on Travis CI.

(object)          istanbul - An object hash containing Istanbul configuration with the following options:
   (string)          command - The Istanbul command to execute (cover, check-coverage, instrument, report).
   (Array<string>)   options - An array of optional parameters which are appended to the invocation of Istanbul.
                               Please run `./node_modules/.bin/istanbul help` for all available options.
                               
(object)          mocha - An object hash containing Mocha configuration with the following options:
   (string)          source - The test source directory.
   (Array<string>)   options - An array of optional parameters which are prepended to the invocation of Mocha. Please
                               run `./node_modules/.bin/mocha --help` for all available options.

When running on Travis CI a test.travis hash in .npmscriptrc may be provided which overrides any data stored in the test hash. This is useful for specifying the coverage command when running on Travis CI.

A basic configuration for testing ES6+ NPM modules in .npmscriptrc follows:

{
   "test":
   {
      // Provides a `coverage` handling command that is appended when running on Travis CI.
      "travis":
      {
         "istanbul": { "command": "cover", "options": ["--report lcovonly"] },
         "report": "./node_modules/.bin/codecov"
      },

      "istanbul": { "command": "cover", "options": ["--include-all-sources --root src"] },
      "mocha": { "source": "./test/src", "options": ["--compilers js:babel-register", "-t 120000 --recursive"] }
   }
}

Please note that you can add comments to .npmscriptrc. Also please note that if you are testing ES6 sources you must include "--compilers js:babel-register" in the mocha options.

By default coverage results from Istanbul are output to ./coverage. The test-coverage.js script only empties ./coverage when executed, so if you change the directory Istanbul outputs to please note that it won't be cleared automatically.