Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grunt jasmine tests fail in terminal but not the browser

I have set up a some tests using grunt and jasmine but am running into a issue when I try and run the tests in terminal. I see this error:

>> Error caught from phantom. More info can be found by opening the Spec Runner in a browser.

When I run the spec runner file in the browser I see that all my tests pass and no error of any kind is shown.

Does anyone know what could be the cause of this issue?

Here is my Gruntfile:

module.exports = function(grunt) {

  grunt.initConfig({

pkg: grunt.file.readJSON('package.json'),

/**
 * Uglify task to minify all javscript files
 * seperating out all script files into a development directory
 * and then having all 'production' scripts within a product directory
 *
 * Note: Will need a bit of work to target the plugins folder
 *       independently to the main apps - as we may have unminified
 *       versions - aswell as our Backbone views.
 */
uglify: {
  options: {
    mangle: false
  },
  files: { 
      src: 'assets/scripts/development/*.js',  // source files mask
      dest: 'assets/scripts/production/',    // destination folder
      expand: true,    // allow dynamic building
      flatten: true,   // remove all unnecessary nesting
      ext: '.min.js'   // replace .js to .min.js
  }
},

/**
 * Sass module compiles all SASS files
 * This quickly avoids having to open and save
 * every single css file if a conflict is present
 */
sass: {
  dist: {
    files: [{
      expand: true,
      cwd: 'assets/styles/sass/',
      src: ['*.scss'],
      dest: 'assets/styles/',
      ext: '.css'
    }]
  }
},

/**
 * Image minification for compressing images
 * accross the project and moving them into their own folder
 * all references once production has gone through points to those
 */
imagemin: {
    png: {
        options: {
            optimizationLevel: 7
        },
        files: [
            {
                expand: true,
                cwd: 'assets/images/',
                src: ['**/*.png'],
                dest: 'assets/images/compressed/',
                ext: '.png'
            }
        ]
    },
    jpg: {
        options: {
            progressive: true
        },
        files: [
            {
                expand: true,
                cwd: 'assets/images/',
                src: ['**/*.jpg'],
                dest: 'assets/images/compressed/',
                ext: '.jpg'
            }
        ]
    }
},

/**
 * PHP Code Standards fixer
 * Runs through the app (main code base for each project)
 * to ensure conforms to a standard
 */
phpcsfixer: {
    app: {
        dir: 'app'
    },
    options: {
        bin: 'php-cs-fixer',
        ignoreExitCode: true,
        level: 'all',
        quiet: false,
        diff: true,
        verbose: true
    }
},

jasmine : {
  src : 'assets/scripts/views/*.js',
  options : {
    specs : 'assets/scripts/tests/*.js'
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-jasmine');
  grunt.loadNpmTasks('grunt-php-cs-fixer');
  grunt.loadNpmTasks('grunt-contrib-imagemin');
  grunt.loadNpmTasks('grunt-contrib-sass');
  // Load the plugin that provides the "uglify" task.
  grunt.loadNpmTasks('grunt-contrib-uglify');

  // Default task(s).
  grunt.registerTask('default', [ 'uglify', 'sass' ] );

  //Jasmine unit tests
  grunt.registerTask('test', [ 'jasmine' ] );

};

Thanks for any help.

like image 563
David Jones Avatar asked Oct 31 '13 16:10

David Jones


1 Answers

I ran into the same issue. In my case the culprit seems to have been the select2 library, but I had to use a process of elimination to figure that out.

Try loading _SpecRunner.html via phantomjs directly, rather than through grunt. I used a basic wrapper script that's essentially the same as what you see on the PhantomJS homepage so that I could chip away the script tags in the runner one by one until I had something that didn't throw the syntax error.

You may also get some further details about the source of the error if you run the grunt task with --force.

I wasn't able to determine the root cause of the error.

like image 190
Bill Avatar answered Oct 11 '22 01:10

Bill