2013-05-05 39 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'); 
}); 
相關問題