Skip to content

An Extension for Visual Studio Code to Run and Debug CucumberJS Tests

License

Notifications You must be signed in to change notification settings

aristotelos/cucumber-test-extension

 
 

Repository files navigation

Logo CucumberJS Test Extension

build

This extension integrates CucumberJS with Visual Studio Code Test Runner.

Features

Seamlessly integrates with Visual Studio Code new Test Runner showing all files in your workspace and a detailed view of all:

  • Features
  • Scenarios
  • Steps

Test runner screenshot

Test Result in .feature files

You can view which steps passed or failed directly in your .feature files, and with the help of the official Cucumber extension you can Ctrl + click to navigate to your failing step.

Feature file screenshot

Inline error details

After running the test you will see an inline report of the failing tests with extensive details of the error and an history of test results.

Inline errors screenshot

Debug an entire feature or a single scenario

You can even debug your tests directly from the Test Runner UI, just click the Debug Test action on a Feature or a Scenario!

Debug screenshot

Search by @Tags

We support searching and filtering tests by @Tag (Thanks to psethwick)

Tags screenshot

Override environment variables

You can specify environment variables in your settings.json file, so that when you run your tests those variables will be defined.

{
    "cucumberTestExtension.env": {
        "MY_VARIABLE_1": "foo",
        "MY_VARIABLE_2": "bar"
    }
}

Custom cucumber profile

You can select a profile to run the tests

const common = {
    require: ["features/**/*.{js,ts}"],
    requireModule: ["ts-node/register"],
    publishQuiet: true,
};

module.exports = {
    default: {
        ...common,
        paths: ["features/**/*.feature"],
    },
    customProfile: {
        ...common,
    },
};
{
    "cucumberTestExtension.profile": "customProfile"
}

Set current working directory for runner

If you have your cucumber tests nested in your development project you may want to specify the current working directory cucumber is running in:

├── src
│   ... your source code
├── specs
│   ├── cucumber.yml
│   ├── tsconfig.json
│   ├── features
│   ├── steps
│   ├── ...
└── .gitignore

You can set the current working directory to cucumber and still have the test explorer for your whole application:

{
    "cucumberTestExtension.workingDirectory": "./specs"
}

Set root directory

The Cucumber JS tool is expected to be present in the node_modules directory. If you are using node_modules only for your specs, it may be in a subdirectory, for example:

├── x
├── y
├── specs
│   ├── features
│   ├── node_modules
│   ├── steps
│   ├── cucumber.yml
│   ├── package.json
│   ├── tsconfig.json
│   ├── ...

You can set the root directory to cucumber and still have the test explorer for your whole application:

{
    "cucumberTestExtension.rootDirectory": "./specs"
}

Error detection and reporting

The extension detects and reports errors in before and after hooks. If possible it reports a problem directly at the line where the error occurred in the source file.

Prerequisites

You need to have a working cucumber-js installation in your working folder and a proper cucumber configuration file. Please follow the documentation on the official cucumber-js website on how to setup the environment.

You need to install the @cucumber/cucumber npm package

npm install @cucumber/cucumber

For typescript support you need to install ts-node

npm install ts-node

Compatibility

The extension has been tested with javascript and typescript.

Example of a cucumber.yml file for a typescript setup:

default:
    features: ["features/**/*.feature"]
    requireModule: ["ts-node/register"]
    require: ["features/**/*.{js,ts}"]
    publishQuiet: true

Known Issues

  • At the moment you cannot undefine an existing environment variable, the only thing you can do is set the variable to an empty string.

About

An Extension for Visual Studio Code to Run and Debug CucumberJS Tests

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 97.9%
  • Gherkin 1.6%
  • JavaScript 0.5%