Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to set up Grunt to automate some testing, testing works fine in the browser but not at the command line

I'm currently trying to incorporate GruntJS with a few plugins (PhantomJS Qunit and Connect plugins). However, setting up a simple test is throwing me errors and I can't find the solution despite a few days of searching. I'm using a local web server (MAMP) and the website is running on a CMS.

Running the tests by accessing the test template in a browser works fine, but when trying to access the same tools via the command line using sudo grunt test PhantomJS return an odd error:

Running "qunit:all" (qunit) task
Testing http://user-guides:80/test/test.html 
Warning: PhantomJS timed out, possibly due to a missing QUnit start() call. Use --force to continue.

Aborted due to warnings.

Some of my searches had people downgrading their version of phantom.js to deal with similar problems, but so far none of those solutions have worked for me, and I'm afraid i'm missing something right in front of my face.

Here's the contents of my Gruntfile.js

    module.exports = function(grunt) {

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),   
        connect: {
            server: {
                options: {
                    hostname: 'user-guides',
                    port: 80,
                    base: 'public'
                }
            }
        },
        jshint: {
            all: ['Gruntfile.js', 'public/assets/js/helper/*.js', 'public/assets/js/specific/*.js']
        },
        qunit: {
        all: {
          options: {
            timeout: 5000,
            urls: [
              'http://user-guides:80/test/test.html',
            ]
          }
        }
    }
    }
    );

    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-qunit');
    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.registerTask('test', ['connect', 'qunit']);
};

Here's the simple Qunit test

<html>
<head>
  <meta charset="utf-8">
  <title>Tests</title>
  <link rel="stylesheet" href="/assets/lib/qunit.css">
</head>
<body>
  <div id="qunit"></div>
  <script src="/assets/lib/qunit.js"></script>

  <script>
console.log("====TEST===");
    start();
    test( "hello test", function() {
      ok( 1 == "1", "Passed!" );
    });
  </script>
</body>
</html>

Any help is greatly appreciated.

like image 644
TrevorP Avatar asked Sep 17 '13 03:09

TrevorP


1 Answers

In my test.html file I originally had just copied the example from the QUnit Cookbook

After finding a similar (possibly the same) issue here: https://stackoverflow.com/a/25053808/1814739

I updated:

<script src="//code.jquery.com/qunit/qunit-1.15.0.js"></script>

to:

<script src="http://code.jquery.com/qunit/qunit-1.15.0.js"></script>

Running from command-line seems to work after adding http: to the src attribute.

like image 129
ooXei1sh Avatar answered Nov 07 '22 13:11

ooXei1sh