Search code examples
phantomjsgruntjsqunitgrunt-contrib-qunit

grunt qunit in conjunction with grunt server


While running grunt server for developing, How can I separately use the grunt qunit task to run the tests. While trying to pass ["test/**/*.html"] to the all property, but that fails to run and returns (Warning: 0/0 assertions ran (0ms) Use)

It looks like, it doesn't fire off a phantomjs instance and doesn't find these pates. So I tried the following

    grunt.initConfig({
     ....  

        qunit: {
            all: {
                options: {
                    urls: ['http://localhost:<%= connect.options.port %>/test/tests/foo.html']
                }
            }
        }
    ....

});

It only works if when manually include all test html pages (like in the example).
The problem is My Question is, can grunt qUnit work properly even while using grunt server. And how can i have ["test/**/*.html"] syntax work correctly. I am sure there must be a better way this should work! Also, how can use grunt.file.expand be utilized to programmatically add matching files to run in the grunt qunit task.


Solution

  • I've done something like this:

    grunt.initConfig({
      ...
      'qunit': {
            'files': ['test/**/*.html']
      }
      ...
    });
    ...
    // Wrap the qunit task
    grunt.renameTask('qunit', 'contrib-qunit');
    grunt.registerTask('qunit', function(host, protocol) {
        host = host || 'localhost';
        protocol = protocol || 'http';
        // Turn qunit.files into urls for conrib-qunit
        var urls = grunt.util._.map(grunt.file.expand(grunt.config.get('qunit.files')), function(file) {
            return protocol + '://' + host + '/' + file;
        });
        var config = { 'options': { 'urls' : urls } };
        grunt.config.set('contrib-qunit.all', config);
        grunt.task.run('contrib-qunit');
    });