GithubHelp home page GithubHelp logo

cucumber / cucumber-js Goto Github PK

View Code? Open in Web Editor NEW
5.0K 213.0 1.1K 27.73 MB

Cucumber for JavaScript

Home Page: https://cucumber.io

License: MIT License

JavaScript 0.30% Shell 0.25% Gherkin 20.71% TypeScript 78.69% Awk 0.05%
cucumber javascript typescript

cucumber-js's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cucumber-js's Issues

Handle pending steps

Missing step definitions trigger ugly "Cannot call method 'invoke' of undefined" exceptions. Fix that!

autorun?

I'd like to run cucumber.js and node (with nodemon) in a manner similar to guard and cucumber_rails. That would mean you'd need some kind of autorun option like jasmin-node does.

Is that a feature on the horizon?

Target specific feature elements

Only execute parts of a feature.

  • FILE:LINE syntax
  • --name
  • --lines

Some existing step definitions depend on this (e.g. When(/^Cucumber executes the scenario "([^"]*)"$/, ...);). Update them as soon as this is finished.

Report undefined step name/stepdef snippet

Missing step definitions are currently marked as "U" (undefined) by the progress formatter without any other kind of information. The user should be told which step (i.e. its name) needs it.

What about the step definition snippet suggestion? I guess many users like those.

Cucumber.js not working on windows7 64bit

Good day
I tried to set the test up with Windows, but it is not working. It works with Mac OS and with Linux.
My node version is 0.6.10

The test is:

Feature: Test

It throws an error when I run the test. The error is: ReferenceError: Test is not defined.

Do you maybe have any suggestions what could be wrong?

Regards,
Channel

Documentation: running Cucumber JS from the browser

Checking out cucumber-js from Github or installing it as a Node module, the example HTML file doesn't work as it is missing browserify and whatever file structure of Node modules it requires.
Some documentation on how to get the example working would be greatly appreciated.

Running the tests: 304 failures

Hi,

I'm running the tests in cucumber-js like this (full steps to eliminate ambiguity):

$ git clone https://github.com/cucumber/cucumber-js.git
$ cd cucumber-js
$ npm install # using --dev fails on browserify. some version problem with connect.
$ sudo npm link
$ node_modules/.bin/jasmin-node spec

894 tests, 1175 assertions, 304 failures

My question is, is there something wrong with my environment, or are these failures expected at the moment?

Handle asynchronous exceptions

Asynchronous exceptions are currently not caught: they interrupt Cucumber execution, print out the stack trace and end the process altogether.

It's possible to catch asynchronous exceptions on both Node.js and browsers through process.on('uncaughtException', ...) and window.onerror, respectively.

The catching function should call the current step callback.fail() function and pass it the caught exception so that Cucumber can report the failing step and proceed with the next scenario, if any.

Interesting Fact™: this will be the first piece of code in Cucumber.js that needs branching depending on wether it's running on Node or a browser.

Example showing how to test a web application

I would like to be able to do something like this:

node cucumber.js features

This will load a web page and all the javascript that it depends on (defined in support/env.js?).

It will then execute all of the features against that loaded web page.

This is the sort of workflow I expected to be able to accomplish with node, but I can't see how to do it.

Any help?

Mike

Handle step failures nicely

Failing steps abruptly halt the execution of the current feature by throwing an exception. Failures should be caught and following steps within the scenario should be skipped. Next scenarios and features should be executed.

I don't know yet if the result of the whole process (success/failure) should be returned to the callback passed to Cucumber.start() or if that responsibility should be left to listeners...

trouble running cucumber-js under windows

have followed the guidance, installed nodejs via msi. file

after that npm install would work only under c:\programfiles \nodejs. and everytime copied my whole workshop folder structure under node.js.

i tried both local and global npm run. after restrating machine i was able to run npm install to run under my workshop as workshopfolder\npm install --dev

it went smooth with instaling

however when i type @node_env=test .. as in guidance. it keep saying that it s not recognized command

however when i type cucumber.js it gives me script error pop up.
saying :

Script:

c.:\ users.currentuser\appdata\roaming\npm\cucumber.js

line:1
char:1
error:invalid character
code:800a03f6
source: miscrosoft jscript compilation error

when i open c.:\ users.currentuser\appdata\roaming\npm\cucumber.js i am having this

!/bin/sh

if [ -x "dirname "$0"/node" ]; then
"dirname "$0"/node" "dirname "$0"/../cucumber/bin/cucumber.js" "$@"
ret=$?
else
node "dirname "$0"/../cucumber/bin/cucumber.js" "$@"
ret=$?
fi
exit $ret


thanks for prompt response #jbpros

Support asynchronous world constructor

I am trying to use cucumber.js to test an express.js web application.
The test scenarios are creating new objects in MongoDb database,
and I need to clear it before running the tests.

Mongodb operations are asynchronous, so if I clear the database
from world constructor, then I have a race condition with test execution.

I came up with an idea how asynchronous initialization can be supported,
please see the fork at git://github.com/salikh/cucumber-js.git.

To request asynchronous initialization, the feature writer needs
to inherit from the EventEmitter by writing the following line:

this.__proto__ = new process.EventEmitter

Then the world constructor can indicate that it finished initialization
by firing an event on itself:

world.emit('init done')

The world initializer tests if the asynchronous initialization is
required by the following condition:

if (world.__proto__.constructor == process.EventEmitter)

and if the condition matches, it starts test execution asynchronously:

world.on('init done', function() {
cont()
})

Use gherkin-editor on example

In order to display the full power of cucumber.js and gherkin-editor combined together, these two should be used on example/index.html.

Display stack traces

When a failure occurs, its stack trace is secretly kept inside Cucumber. It should be displayed to the user so that (s)he can actually fix it!

Add `World`

See https://github.com/cucumber/cucumber/wiki/A-Whole-New-World and #2 (comment)

var assert = require('assert');

var defineSteps = function() {
  // `this` is set to an object supplying Given, When, Then and the World constructor.

  this.World = function World() { this.cukes = 0; }; // this is optional, would default to
                                                     // an empty constructor; kinda similar to
                                                     // cucumber-ruby's Object instance
  this.World.prototype.cukeUp = function() { this.cukes++; };

  this.When(/^I cuke up$/, function(callback) { 
    // `this` is set to the World object
    this.cukeUp();
    callback();
  });

  this.Then(/^I should have (\d+) cukes in my belly$/, function(expectedCukes, callback) { 
    // `this` is set to the World object
    assert.equal(this.cukes, expectedCukes);
    callback();
  });
};
module.exports = defineSteps;

Comments and suggestions are welcome!

Don't pollute global namespace

It would be nice to be able to do something like this:

(function(stepdefs) {
  // Defines Given, When, Then
  stepdefs.register(this);
  // Or maybe we have to do it like this:
  var Given = When = Then = stepdefs.register;

  var cukes;

  Given(/I have (\d+) cukes in my belly/, function(n, callback) {
    cukes = n;
    callback();
  });

  // More stepdefs here...

})(require('cucumber/stepdefs'));

Modularize cucumber.js

The code is currently packaged as a single .js file. This Is Bad™. RequireJS seems to be the answer as it handles modules equally within browsers and Node.js (with fallback to native Node module system).

Add strict mode

Add --strict flag to CLI and equivalent option to volatile configuration.

Async stepdef callbacks don't work

Consider the stepdef in example/index.html:

Given(/a variable set to (\d+)/, function(number, callback) {
  variable = parseInt(number);
  callback();
});

If I replace this with:

Given(/a variable set to (\d+)/, function(number, callback) {
  variable = parseInt(number);
  setTimeout(function() {
    callback();
  }, 0);
});

then I get an exception.

World.js example requires zombie to be assigned to a variable.

Don't forget to assign zombie to a variable for use in your features/support/world.js example.

The example:

require('zombie');
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;

Corrected:

but, zombie isn't assigned until you do it yourself:

var zombie = require('zombie');
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;

i18n

Add support for all Gherkin's spoken languages. The # language: xx comment directive should be recognized.

This will probably impact the undefined step definition snippets.

Progress formatter (CLI)

Currently, cucumber.js CLI uses a bare "pretty" formatter to output results. It displays the source of the feature while it is running. It is too verbose and does not include any summary.

By default, CLI must use a progress formatter that outputs things in a similar fashion than its Ruby brother (dots and chars to indicate step execution results).

Allow World constructor to callback without explicit world instance

This is how the World constructor is now expected to call back:

this.World = function World(callback) {
  callback(this);
}

Calling back without a parameter is currently forbidden, leading to an exception:

this.World = function World(callback) {
  callback(); // error!
}

Cucumber is using the new keyword when calling the World() function. It means it could (and should) use the fresh World instance when no explicit one is passed to the callback.

this.World = function World(callback) {
  callback(); // would be the same as: callback(this)
}

Supporting step definitions assertions in callbacks

Given step definitions currently rely on failures in step definitions to be synchronous:

support_code/step_definitions.js:19

      try {
        code.apply(world, parameters);
      } catch (exception) {
        if (exception)
          Cucumber.Debug.warn(exception.stack || exception, 'exception inside feature', 3);
        var stepResult;
        if (exception instanceof Cucumber.Runtime.PendingStepException)
          stepResult = Cucumber.Runtime.PendingStepResult()
        else
          stepResult = Cucumber.Runtime.FailedStepResult(exception);
        callback(stepResult);
      }

It's not possible to handle assertions that need to be made in callbacks, which is the case when using phantomjs as the bridge is asynchronous. So:

this.browser.evaluate(function(){ "$('#id').length"}, function(result) {
  result.should.not.eql(0)
});

Won't fail the scenario if the assertion fails.

Seems like the best approach is to support firing an error event in the case of doing assertions in callbacks (as well as directly throwing exceptions in step definitions. Thoughts? Happy to work on this once we flush out the ideal approach.

Convert data table values to intended data types

Right now the data table parser assumes everything is a string and users have to manually convert fields to Booleans, objects, arrays, etc. More than willing to help out on this if you can point me in the right direction.

I've traced it back to this line:

https://github.com/cucumber/cucumber-js/blob/master/lib/cucumber/type/hash_data_table.js#L33

It looks like Gherkin is actually converting everything to strings, so I'm not sure if that's a bug or something intentional.

Unify features with cucumber-features

cucumber-features + Aruba is now the official way of testing cucumber.js. This is great. But it would even be nicer to have cucumber.js test itself again, like in its early days. Remember: it emerged by testing itself :)

To achieve this we need:

  • JS step definitions for cucumber-features (this is easy, those already exist within cucumber_js_mappings.rb)
  • create the JS mappings between those step definitions and the features ("step definitions of step definitions")
  • remove redundant features from cucumber-js/features (e.g. progress_formatter.feature); we should keep the number of implementation-dependent features to a minimum, imho.
  • remove old JS step definitions

Of course, running cucumber-features with cucumber.js won't generate the nice documentation we get from Aruba.

Also, the step definitions won't run the cucumber.js CLI but will directly load a Cucumber.js instance in-memory. At least for now.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.