Socket
Book a DemoInstallSign in
Socket

grunt-nyc-mocha

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-nyc-mocha

grunt task for running tests and coverage, based on nyc and mocha.

1.2.0
latest
Source
npmnpm
Version published
Weekly downloads
147
-58%
Maintainers
0
Weekly downloads
 
Created
Source

grunt-nyc-mocha

grunt task for running tests and coverage, based on nyc and mocha.

npm version License: MIT jsdoc Built with Grunt codecov Build Status dependencies

content

Changelog

getting started

This guide assumes, that you are familiar with the use of npm and grunt.
The plugin can be installed by the following command:

npm install grunt-nyc-mocha --save-dev

Once installed, the plugin may be loaded from within your gruntfile.

task nyc_mocha

"nyc_mocha" is a grunt multitask provided by grunt-nyc-mocha and can hold multiple targets. Each of the targets you may define will spawn their very own node process.

Multitask configuration generally splits into the following parts:

Any target can extend, repeat or overwrite options previously defined by a task. For doing so, each target can specify its own "options" property. Targetlevel options will be merged into tasklevel options, overwriting them.

raw usage of grunt-nyc-mocha

// extract from gruntfile.js

module.exports = function( grunt ) {
  grunt.initConfig({
    // among many others ...
    nyc_mocha:{
      options: { /*tasklevel options go here*/ }
      target:  {
        src: "./src/test/**/*.spec.js", // test suites to run...
        options: { /* targetlevel options go here */ }
      }
    }
  });

  grunt.loadNpmTasks( "nyc_mocha" );

  grunt.registerTask( "default", [ "nyc_mocha:target" ]);
}

using grunt-nyc-mocha with load-grunt-config and load-grunt-tasks

Install the following packages:
npm install load-grunt-config --save-dev
npm install load-grunt-tasks --save-dev

Now you can split gruntfile.js in multiple configuration files:

// extract from (a much cleaner) gruntfile.js
const configPath = ...? // this is where your config files reside
const data       = { /* some properties, that can be passed on */ };

module.exports = function( grunt ) {
  require( "load-grunt-config" )( grunt, { configPath, data });
  require( "load-grunt-tasks"  )( grunt );

  grunt.registerTask( "default", [ "nyc_mocha:target" ]);
}
// extract from nyc_mocha.js (has to be named tasklike!)
module.exports = function ( grunt, options ) {
  return {
    target: {
      src: "./src/test/**/*.spec.js", // run those test files
      options: {
        nyc: {
          coverage: {                                 // report nyc coverage results
            dir:          "dist/coverage",            // ... to folder
            reporter:     [ "html", "text-summary" ]  // ... using reporters
          },
          excludes:       [ "**/*.spec.js" ],         // exclude test files from instrumentation!
          requires:       [ "grunt-nyc-mocha/scripts/sourcemapsupport" ]
        },
        mocha: {
          color:          true                        // force colored output
        }
      }
    }
  }
};

Keywords

grunt

FAQs

Package last updated on 01 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.