我如何使用GruntJS运行一个特定的CucumberJSfunction?
我使用CucumberJS在我的NodeJSnetworking应用程序上运行testing。
目前,我可以使用grunt cucumberjs
执行grunt
,或者只执行CucumberJS任务来运行所有的咕噜任务。
但是现在我只想执行特定的function。
例如,说我有以下function文件:
- Signin.feature
- Favourite.feature
我只想运行最喜欢的functiontesting,使用如下命令:
grunt cucumberjs Favourite
这可能吗?
顺便说一句,这是我的gruntfile.js
:
'use strict'; module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), ... cucumberjs: { src: 'features', options: { steps: 'features/step_definitions', format: 'pretty' } } }); ... grunt.loadNpmTasks('grunt-cucumber'); grunt.registerTask('default', [... 'cucumberjs']); };
我终于find了一个解决scheme,似乎工作得很好,基于标签 。
所以对于我的每个function文件,我都添加了一个标签。
例如,对于Favourite.feature:
@favourite Feature: Favourite As a user of the system I would like to favourite items
然后我使用了一个GruntJS选项来指定我想通过命令行参数运行的标签。
我通过在grunt.option()
调用来做到这一点:
cucumberjs: { src: 'features', options: { steps: 'features/step_definitions', format: 'pretty', tags: grunt.option('cucumbertags') } }
所以现在我可以像这样从命令行运行GruntJS:
grunt cucumberjs --cucumbertags=@favourite
它只会使用@favourite标签运行该function。 好极了!
这里是我的任务,允许你通过feature.name过滤:
https://github.com/webforge-labs/cuked-zombie/blob/master/tasks/cucumber.js (下载到“任务”文件夹,你可以加载它: grunt.loadTasks('tasks')
)
像这样configuration(Gruntfile.js):
grunt.loadNpmTasks('grunt-cucumber'); grunt.initConfig({ cucumberjs: { // config for all features when called with: `grunt cucumber` all: { src: 'features', options: { steps: "tests/js/cucumber/bootstrap.js", format: "pretty" } }, // config for single features when called with `grunt --filter some-feature` features: { src: 'features', options: { steps: "tests/js/cucumber/bootstrap.js", format: "pretty" } } } });
使用它:
grunt cucumber --filter post
这将运行post.feature(在您的function目录中的某个地方)
有了新的黄瓜-js版本,可以通过特征线来运行它: https : //github.com/cucumber/cucumber-js/pull/168