Pure Javascript Cucumber
JavaScript Ruby
Clone or download
Pull request Compare This branch is 8 commits ahead, 768 commits behind cucumber:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Cucumber.js Build Status

Cucumber, the popular Behaviour-Driven Development tool, brought to your JavaScript stack.

It runs on both Node.js and modern web browsers.

Try it now: http://cucumber.no.de!

Development status

Cucumber.js is still a work in progress. Here is its current status.

Cucumber Technology Compatibility Kit

Feature Status
Core (scenarios, steps, mappings) Done
Background Done1
Calling steps from step defs To do
Comments Done
Command-line interface Done1, 2
Command-line options To do2
Data tables Done
Doc Strings Done
Failing steps Done
Hooks WIP3
I18n To do
JSON formatter To do
Pretty formatter To do2
Scenario outlines and examples To do
Stats collector To do
Step argument transforms To do
Tags To do
Undefined steps Done
Wire protocol To do
World Done
  1. Not certified by Cucumber TCK yet.
  2. Considered for removal from Cucumber TCK.
  3. Simple Before and After hooks are available.

Cucumber.js-specific features

Feature Status
Background Done1
CoffeeScript support Done
Command-line interface Done
  1. Will be certified by Cucumber TCK.


Cucumber.js is tested on:

  • Node.js 0.4, 0.6 (see CI builds) and supposedly 0.5.
  • Google Chrome
  • Firefox
  • Safari
  • Opera

There are plans to have CI builds on browsers too.



Cucumber.js is available as an npm module.

Install globally with:

$ npm install -g cucumber


You may also define cucumber.js as a development dependency of your application by including it in a package.json file.

// package.json

{ "devDependencies" : {
    "cucumber": "latest"

Then install with npm install --dev


Features are written with the Gherkin syntax

# features/myFeature.feature

Feature: Example feature
  As a user of cucumber.js
  I want to have documentation on cucumber
  So that I can concentrate on building awesome applications

  Scenario: Reading documentation
    Given I am on the cucumber.js github page
    When I go to the README file
    Then I should see "Usage"

Support Files

Support files let you setup the environment in which steps will be run, and define step definitions.


World is a constructor function with utility properties, destined to be used in step definitions

// features/support/world.js

var World = function(callback) {
  this.browser = new zombie.Browser(); // this.browser will be available in step definitions

  this.visit = function(url, callback) {
    this.browser.visit(url, callback);

  callback(this); // tell Cucumber we're finished and what to use as World (this)
exports.World = World;

Step Definitions

Step definitions are the glue between features written in Gherkin and the actual SUT (system under test). They are written in JavaScript.

All step definitions will run with this set to what is known as the World in Cucumber. It's an object exposing useful methods, helpers and variables to your step definitions. A new instance of World is created before each scenario.

Step definitions are contained within one or more wrapper functions.

Those wrappers are run before executing the feature suite. this is an object holding important properties like the Given(), When() and Then() functions. Another notable property is World; it contains a default World constructor that can be either extended or replaced.

Step definitions are run when steps match their name. this is an instance of World.

// features/step_definitions/myStepDefinitions.js

var myStepDefinitionsWrapper = function() {
  this.World = require("../support/world.js").World; // overwrite default World constructor

  this.Given(/REGEXP/, function(next) {
    // express the regexp above with the code you wish you had
    // this is set to a new this.World instance
    // i.e. you may use this.browser to execute the step...

    this.visit('http://github.com/cucumber/cucumber-js', next);

  this.When(/REGEXP/, function(next) {
    // express the regexp above with the code you wish you had
    // Call next() at the end of the step, or next.pending() if the step is not yet implemented.

  this.Then(/REGEXP/, function(next) {

module.exports = myStepDefinitionsWrapper;

Before and After hooks

If you need to execute some code before or after each scenario, you can use hooks, just like this:

// features/step_definitions/myStepDefinitions.js

var myStepDefinitionsWrapper = function() {
  this.Before(function(callback) {
    // this is an instance of World, just like within step definitions

  this.After(function(callback) {

  // ...

module.exports = myStepDefinitionsWrapper;

Run cucumber

Cucumber.js includes a binary file to execute the features.

If you installed cucumber.js with npm install --dev, you may run cucumber with:

  @NODE_ENV=test ./node_modules/.bin/cucumber.js

You may specify the features to run:

  @NODE_ENV=test ./node_modules/.bin/cucumber.js features/myFeature.feature

And require specific step definitions with the --require option:

  @NODE_ENV=test ./node_modules/.bin/cucumber.js features/myFeature.feature \
    --require features/step_definitions/myStepDefinitions.js


A few example apps are available for you to browse:

Setup for using in Node.js and running tests

Install the required dependencies:

$ npm link


$ node example/server.js

Then go to localhost:9797.

Run tests


$ node_modules/.bin/jasmine-node spec

Features & documentation

There is a common set of features shared by all cucumber implementations. It's called the Technology Compatibility Kit or TCK. Find more on the Cucumber TCK repository.

The official way of running them is through Cucumber-ruby and Aruba. Ruby and Bundler are required for this to work.

$ git submodule update --init
$ bundle
$ rm -rf doc; ARUBA_REPORT_DIR=doc cucumber features/cucumber-tck -r features

Note: you need the bcat and rdiscount gems in order to use the ARUBA_REPORT_DIR environment variable. Install it with gem install bcat rdiscount.

You can then open the generated documentation:

$ open doc/features/cucumber-tck/*.html # might open a lot of files ;)

In addition to that, Cucumber.js is able to run the features for itself too:

$ ./bin/cucumber.js features/cucumber-tck -r features

There are a few other Cucumber.js-dependent features. Execute everything:

$ ./bin/cucumber.js


Alternatively, you can run everything with the help of Rake:

$ git submodule update --init
$ bundle
$ rake

Debug messages

You can display debug messages by setting the DEBUG_LEVEL environment variable. It goes from 1 to 5. 5 will diplay everything, 1 will only print out the critical things.

$ DEBUG_LEVEL=5 ./bin/cucumber.js

It even works with Aruba:

$ rm -rf doc; DEBUG_LEVEL=5 ARUBA_REPORT_DIR=doc cucumber features/cucumber-tck -r features
$ open doc/features/cucumber-tck/*.html # you'll see debug messages in Aruba-generated docs

Help & support

Release checklist

  • Update History.md
  • Bump version in lib/cucumber.js
  • Bump version in package.json
  • Add new contributors to package.json, if any
  • Commit those changes as "Release 0.1.2" (where 0.1.2 is the actual version, of course)
  • Tag commit as "v0.1.2" with short description of main changes
  • Push to main repo on Github
  • Publish to NPM
  • Deploy to cucumber.no.de