Running grunt task multiple times until it fails

烂漫一生 提交于 2019-12-25 07:46:30

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/36960934/running-grunt-task-multiple-times-until-it-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!