Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best workflow for running jasmine tests on production code with grunt?

I've scoured the internet looking for a description of the thing I'm trying to do but to no avail. I would like to get unit tests in place for a web frontent I'm building that run directly on the production code by loading it with PhantomJS from the localhost. I'd like to run a Grunt task that goes through my specs after loading the real site and interacting with the dom to test everything out. I'm ALMOST there, but I can't actually get the page to load.

If I add a host item to the jasmine options in my gruntfile like so:

options: {
        specs: 'spec/*Spec.js',
        helpers: 'spec/*Helper.js',
        vendor: ['app/assets/javascripts/src/libs/jquery-1.9.1.min.js', 'app/assets/javascripts/src/libs/underscore.js'],
        template: require('grunt-template-jasmine-requirejs'),
        host: "http://localhost:3000"
      }

I get a timeout error every time. Nobody's really addressed this issue in the Grunt context, so I'm not sure what the story is, and I have no asynchronous tests running. If I leave hosts out, it runs the tests successfully, but only on my raw javascript files through the local filesystem, not over the local network. How do I configure my templates to allow Jasmine tests to run over a different host?

UPDATE:

Actually, it looks like Grunt doesn't actually poll against the local server, it just hangs and times out.

like image 445
user768680 Avatar asked Mar 07 '13 20:03

user768680


1 Answers

you need to start a local server using grunt-contrib-connect

specify in your config:

grunt.initConfig({
  connect: {
    server: {
      options: {
        port: 3000
      }
    }
  }  
});    

add to an alias task:

grunt.registerTask("default", ["connect", "your-jasmine-task"]);

and run it:

$ grunt default
like image 71
hereandnow78 Avatar answered Sep 21 '22 13:09

hereandnow78