grunt qunit与grunt服务器一起使用

时间:2013-05-05 20:48:20

标签: phantomjs gruntjs qunit grunt-contrib-qunit

在运行grunt server进行开发时,如何单独使用grunt qunit任务来运行测试。 尝试将["test/**/*.html"]传递给all属性,但无法运行并返回(Warning: 0/0 assertions ran (0ms) Use

看起来,它并没有触发phantomjs实例并且找不到这些pates。 所以我尝试了以下

    grunt.initConfig({
     ....  

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

});

仅当手动包含所有测试html页面时才有效(如示例中所示) 问题是 我的问题是,即使使用grunt服务器,也可以使qUnit正常工作。 我怎样才能使["test/**/*.html"]语法正常工作。我相信一定有更好的方法可行! 另外,如何使用grunt.file.expand以编程方式添加匹配文件以在grunt qunit任务中运行。

1 个答案:

答案 0 :(得分:1)

我做过这样的事情:

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');
});