Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run one particular CucumberJS feature using GruntJS?

I'm using CucumberJS to run tests on my NodeJS web app.

At the moment, I can run all of my grunt tasks by executing grunt, or only the CucumberJS tasks, using grunt cucumberjs.

But now I want to only execute particular features.

For example, say I have the following feature files:

  • Signin.feature
  • Favourite.feature

I want to only run the Favourite feature tests, using a command such as:

grunt cucumberjs Favourite

Is this possible?


BTW, here's my 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']);
};
like image 726
Jonathan Avatar asked Feb 04 '14 05:02

Jonathan


1 Answers

I finally figured out a solution that seems to work well enough, based on tags.

So for each of my feature files, I've added a tag.

For example, for Favourite.feature:

@favourite
Feature: Favourite
    As a user of the system
    I would like to favourite items

Then I've used a GruntJS option to specify the tags I want to run via a command-line argument.

I do this through a grunt.option() call in my gruntfile:

cucumberjs: {
    src: 'features',
    options: {
        steps: 'features/step_definitions',
        format: 'pretty',
        tags: grunt.option('cucumbertags')
    }
}

So now I can run GruntJS from the command-line like this:

grunt cucumberjs --cucumbertags=@favourite

And it will only run the feature with the @favourite tag. Yay!

like image 90
Jonathan Avatar answered Sep 24 '22 19:09

Jonathan