請考慮connect
的這部分配置(更確切地說,這是connect
一個子任務):
test : {
options : {
middleware : function(connect) {
return [
require('connect-livereload')(),
mountFolder(connect, '.tmp'),
mountFolder(connect, 'test')
];
},
port : grunt.option('port') ? Number(grunt.option('port')) + 1 : 9001
}
}
以上將來自可通過HTTP指定的文件夾中生成文件。
.tmp
是我的transpiled的CoffeeScript和SCSS是登陸定期JS/CSS
test
是在我的測試中有一個非常簡單的index.html
文件,其中電線一起駐留所有的JS/CSS在一起,包括mocha.js
和mocha.css
在我Gruntfile後來我註冊test
任務:
grunt.registerTask('test', function(target) {
var tasks = [
'clean:server',
'coffee',
'jst',
'connect:test'
];
if (target === 'browser') {
tasks.push('open:test');
tasks.push('watch');
} else {
tasks.push('mocha');
}
grunt.task.run(tasks);
});
這是有關您的問題的一部分是'connect:test'
這使得可以通過瀏覽器訪問測試,而這一次:
if (target === 'browser') {
tasks.push('open:test');
tasks.push('watch');
} else {
tasks.push('mocha');
}
只要你不指定browser
爲您test
目標時,測試將在控制檯中無端運行。但如果你喜歡grunt test:browser
,Grunt將會打開瀏覽器,感謝open:test
。爲了您的參考,我還包括我的open:test
config:
test : {
path : 'http://localhost:<%= connect.test.options.port %>'
}
太棒了!我會盡快嘗試。 – darksoulsong