Skip to content

Instantly share code, notes, and snippets.

@paolocarrasco
Last active December 28, 2015 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paolocarrasco/7507024 to your computer and use it in GitHub Desktop.
Save paolocarrasco/7507024 to your computer and use it in GitHub Desktop.
How to use the Bower installation command in Grunt before the execution of the tests.

As I needed to run the bower installation before my tests run in the CI (I use Travis-CI), I had to implement a custom task in Grunt to do so; the issues I had with the grunt tasks I found out there was that they didn't do the simplest thing: run the install command. This is an easy thing and it doesn't require any plugin. It's very important the event 'end' and the async method. The task won't finish successfully without it. You can see the complete gruntfile here

/*global require */
module.exports = function(grunt) {

  // ...
  // ... here are registered the other tasks
  // ...
  
  grunt.registerTask('bower_install', function() {
    var bower = require('bower');
    var endOfTask = this.async();

    bower.commands
      .install()
      .on('end', endOfTask);
  });

  // Default task.
  grunt.registerTask('default', ['jshint', 'bower_install', 'mocha_phantomjs']);

};
@paolocarrasco
Copy link
Author

another way to install Bower dependencies would be following the advice here. I think the advice is a better solution, because it helps to run Bower in a Heroku environment, but the issue would be that Bower should be moved to your dependencies (not devDependencies). If that's not an issue, go for it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment