多次运行grunt任务直到失败 [英] Running grunt task multiple times until it fails
问题描述
我是不是经常连续运行同一个grunt任务的规范方法, d喜欢将问题保留为泛型,但这里有一个具体的用例:
我们有一大批用Protractor编写的端到端测试,我们通过它运行 grunt
借助 grunt-protractor-runner
和 咕噜-的contrib-连接
。我们想要做的是保持连接
任务运行(Web服务器从 dist
目录服务) ),同时遍历量角器
,直到它失败(或/和高达 N
次)。任务:
connect:{
test:{
options:{
base: 'dist',
端口:9001
}
},
},
量角器:{
选项:{
keepAlive:true,
noColor:false
},
local:{
options:{
configFile:test / e2e / config / local.conf.js
$ b grunt.registerTask('e2e:local',[
'connect:test',
'量角器:本地'
]);
在这里,我们要执行 connect:test
一次和量角器:本地
多次。
Turn就像将任务添加到任务数组N次一样简单(仍然不确定是否可以避免指定 N
并无限期地运行任务直到失败),因为默认 grunt
在fail-fast模式下工作,所以整个任务在第一次失败时会失败。在我们的例子中:
grunt.registerTask('e2e:local',function(){
var tasks = [ 'connect:test'];
var N = 100;
for(var i = 0; i< N; i ++){
tasks.push('protractor:本地')
}
grunt.task.run(任务);
});
N
这里是硬编码的任务,但可以作为 grunt选项从外部传递。
What is the canonical way to run the same grunt task continuously, multiple times until it fails?
I'd like to keep the question generic, but here is a specific use case:
We have a huge set of end-to-end tests written in Protractor which we run via grunt
with the help of grunt-protractor-runner
and grunt-contrib-connect
. What we'd like to do is to keep the connect
task running (the web-server serving from a dist
directory) while looping over the protractor
until it fails (or/and up to N
times). The tasks:
connect: {
test: {
options: {
base: 'dist',
port: 9001
}
},
},
protractor: {
options: {
keepAlive: true,
noColor: false
},
local: {
options: {
configFile: "test/e2e/config/local.conf.js"
}
}
},
grunt.registerTask('e2e:local', [
'connect:test',
'protractor:local'
]);
Here, we'd like to execute connect:test
once and protractor:local
multiple times.
Turns out to be as simple as adding the same task to the array of tasks N times (still not sure if we can somehow avoid specifying the N
and run the task indefinitely until it fails) and, since, by default grunt
works in the "fail-fast" mode, the whole task would fail on the first fail. In our case:
grunt.registerTask('e2e:local', function () {
var tasks = ['connect:test'];
var N = 100;
for (var i = 0; i < N; i++) {
tasks.push('protractor:local')
}
grunt.task.run(tasks);
});
N
here is hardcoded inside the task, but could be passed "from outside" as a grunt option.
这篇关于多次运行grunt任务直到失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!