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

grunt-run-task

v1.0.0

Published

Run Grunt tasks in you tests, so you can test them

Downloads

58

Readme

grunt-run-task

Run Grunt tasks in you tests, so you can test them.

So you want to test your Grunt tasks, eh? And you don't want to litter your project’s Gruntfile with tasks that are needed “just for the tests”? And you want your tests to be self-contained? Then this module is for you!

Whatsitdo?

This package gives you the tools to run Grunt tasks inside your tests and clean up afterwards. You can use your test tool’s setup and tear down methods to run the Grunt task you want to test with arbitrary configuration.

If you’re using BDD it could look like this:

var assert = require('assert');
var grunt = require('grunt');
var runTask = require('grunt-run-task');

describe('my awesome Grunt task', function () {
  runTask.loadTasks('tasks');

  describe('when using the default options', function () {
    var task = runTask.task('awesome_task', {
      options: {},
      src: [ 'test/fixtures/src.js' ],
      dest: 'tmp/src.out.js'
    });

    beforeEach(task.run());
    afterEach(task.clean());

    it('does awesome stuff', function() {
      assert(grunt.file.exists(task.files[0].dest));
    });
  });
});

Installation

This module is tested with Grunt 0.4.x and Node.js 0.10.x, 0.11.x and 0.12.x. Use npm to install it:

npm install --save-dev grunt-run-task

API

runTask(name, config, done)

Run the given task immediately with the given config. Call the callback, once the task has finished. Returns the created Task instance.

Options

  • name String The name of the task to run. This may include colon-separated arguments to pass to the task, or, in the case of multi-tasks, the name of the target to run.
  • config Object The configuration to use for the task.

Example

Run the jshint task.

runTask.loadNpmTasks('grunt-contrib-jshint');
runTask('jshint:default', {
  // JSHint is a multi-task, setup the "default" target
  default: {
    files: [ '**/*.js' ]
  }
}, function (err, task) {
  if (err) {
    // The task did encounter an error
  }
});

runTask.task(name, [config])

Return a new Task object that can be used to run the given task.

Options

  • name String The name of the task to run. This may include colon-separated arguments to pass to the task, or, in the case of multi-tasks, the name of the target to run.
  • config Object The configuration to use for the task.

Example

Run the uglify task, and cleanup created files afterwards.

runTask.loadNpmTasks('grunt-contrib-uglify');
var task = runTask.task('uglify', {
  default: {
    files: {
      'build/app.js': [ '**/*.js' ]
    }
  }
});

task.run('default', function (err) {
  task.clean(function (err) {
    // Done
  });
});

runTask.grunt

The (internal) Grunt instance used for running your tasks. You can use this if you want to test if your task called the Grunt API or modified some configuration entries. This will not be the same instance you would obtain with require('grunt').

runTask.initConfig(configObject)

Wrapper for the grunt.initConfig method.

runTask.registerTask(taskName, ...)

Wrapper for the grunt.registerTask method.

runTask.registerMultiTask(taskName, ...)

Wrapper for the grunt.registerMultiTask method.

runTask.registerInitTask(taskName, ...)

Wrapper for the grunt.registerInitTask method.

runTask.renameTask(oldTaskName, newTaskName)

Wrapper for the grunt.renameTask method.

runTask.loadTasks(tasksPath)

Wrapper for the grunt.loadTasks method.

runTask.loadNpmTasks(pluginName)

Wrapper for the grunt.loadTasks method.

runTask.option(pluginName)

Wrapper for the grunt.option method.

Class: Task

The task class implements the EventEmitter2 API. Any events that are emitted by Grunt while your task runs are forwarded to the task class.

Properties

  • name String The name of the task.
  • multi Boolean Whether this is a multi-task.
  • init Boolean Whether this is a init-task
  • target String If the task is a multi-task, this is the target name it was created with.
  • args Array Any arguments that were passed when creating the task.
  • files Array The destination files that this task (might have) created.

task.run([arguments...], [done])

Run the task with the given arguments. If the last argument is a function, run the task immediately and call the function once the task finished. Otherwise, return a function expecting a single parameter, the callback, that actually runs the task.

Options

  • arguments String Any arguments to pass to the task, similar to what you would specify on the command line, by appending colon-separated options to the task you wish to run.
  • done Function A callback to be called once the task has finished.

task.fail([arguments...], [done])

Run the task with the given arguments, but expect it to fail. If the last argument is a function, run the task immediately and call the function once the task finished. Otherwise, return a function expecting a single parameter, the callback, that actually runs the task.

Options

  • arguments String Any arguments to pass to the task, similar to what you would specify on the command line, by appending colon-separated options to the task you wish to run.
  • done Function A callback to be called once the task has finished.

task.clean([done])

Clean up the task's dest files.

Options

  • done Function A callback to be called once all files have been removed.

License

Copyright © 2014 Jonas Pommerening

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.