Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 1.3.1 breaks on babel-node polyfied environment #652

Closed
armandabric opened this issue Oct 14, 2016 · 6 comments
Closed

Version 1.3.1 breaks on babel-node polyfied environment #652

armandabric opened this issue Oct 14, 2016 · 6 comments

Comments

@armandabric
Copy link

I'm trying to upgrade cucumber from v1.2.2 to v1.3.1. But the new version seems to not be compatible my installation.

I'm using cucumberjs with ES2015 step files. For now, I'm using babel-node to polyfill the environment:

$ node --harmony ./node_modules/.bin/babel-node ./node_modules/.bin/cucumberjs

After upgrading to the v1.3.1 version, I've an error throw at startup:

$ node --harmony ./node_modules/.bin/babel-node ./node_modules/.bin/cucumberjs
/app/features/fixtures/EventSourcing/Car.js:27
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
                                                                                            ^

TypeError: Cannot call a class as a function
    at _classCallCheck (/app/features/fixtures/EventSourcing/Car.js:27:99)
    at Object.Car (/app/features/fixtures/EventSourcing/Car.js:12:50)
    at /app/node_modules/cucumber/lib/cucumber/cli/support_code_loader.js:67:33
    at Array.forEach (native)
    at Object.wrapper (/app/node_modules/cucumber/lib/cucumber/cli/support_code_loader.js:62:15)
    at Object.initializer (/app/node_modules/cucumber/lib/cucumber/cli/support_code_loader.js:24:41)
    at Object.Library (/app/node_modules/cucumber/lib/cucumber/support_code/library.js:133:25)
    at Object.getSupportCodeLibrary (/app/node_modules/cucumber/lib/cucumber/cli/support_code_loader.js:10:58)
    at Object.getSupportCodeLibrary (/app/node_modules/cucumber/lib/cucumber/cli/configuration.js:128:32)
    at Object.getSupportCodeLibrary (/app/node_modules/cucumber/lib/cucumber/runtime.js:44:46)

The Car.js file is directly imported in one of my step file import Car from './../fixtures/EventSourcing/Car'; and looks like this: https://gist.github.com/Spy-Seth/2fed28afa3e96e8ee7a1946a1c1e43b3 (a simple exported ES2015 class).

I do not find a way to make this configuration working with the new version of cucumbejs. Do I do wrong something?

@charlierudolph
Copy link
Member

charlierudolph commented Oct 14, 2016

1.3.0 added es6 export default function module support.

Every support file is required and if it exports a function, then it calls it. The problem is as what you ran into when you classes since they are technically functions. This has been something I've disliked about cucumber-js.

One workaround for this (which should probably just be the suggested project setup) is to put any helper classes in a different folder and use --require for complete control of what cucumber-js loads. For example make your default profile require feature/step_definitions and features/support (which holds the hook / world / timeout configs) while your classes and other files which cucumber-js shouldn't require directly live in another folder like features/helpers. cucumber-js could then validate all required files export a function.

@armandabric
Copy link
Author

Thanks for your answer.

As I understand the solution for small project, it seems to be really complicated to do in a big project:I will have to many required file to manage to have all my features working.

I'm not sure about the right solution for people who a doing ES2015 (or more recent): an option to disable this feature and let the user to use babel-node (like I did), or make cucumber reusing the project babel configuration (like https://github.com/avajs/ava does for example).

@charlierudolph
Copy link
Member

Can you explain more the possible solutions you are thinking about? I don't see this issue as being babel specific.I think it would be good to change how cucumber loads step definitions and other things to not just run any exported function but I'm uncertain at the moment how to do that. I'll create a new issue to track this.

@armandabric
Copy link
Author

In a more thought, if you are familiar with PHP, the Behat project have strong proposal on how to deal with step definition and world (they call it context, and are multiple). Their proposal lead to more structure and forbid a lot of usage (generally wrong usage). It also imply that the library (here cucumber-js) has more job to do. I not saying that this library should follow this path but it is an idea.

Instead of automatically load file, you could look on being more configurable. It could help to avoid auto-loading.

@charlierudolph
Copy link
Member

Discussion moved to #679

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants