2013-05-05 50 views
2

运行grunt server进行开发时,如何单独使用grunt qunit任务来运行测试。 虽然试图通过["test/**/*.html"]all财产,但无法运行和返回(Warning: 0/0 assertions ran (0ms) Usegrunt qunit与grunt服务器联合使用

看起来,它不把火关phantomjs实例,并没有找到这些馅饼。 所以我尝试以下

grunt.initConfig({ 
    .... 

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

}); 

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

回答

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