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

allow cucumber-preset modules under require-module #1641

Closed
zanona opened this issue Apr 13, 2021 · 5 comments
Closed

allow cucumber-preset modules under require-module #1641

zanona opened this issue Apr 13, 2021 · 5 comments
Assignees
Labels
🐛 bug Defect / Bug ✅ accepted The core team has agreed that it is a good idea to fix this
Milestone

Comments

@zanona
Copy link

zanona commented Apr 13, 2021

I am trying to create an external module where I can set up a preset for running cucumber test.
This external module has @cucumber/cucumber as a peerDependency, so it doesn't install it directly. Therefore, this dependency allows the preset to set the World constructor as well as add Given, When, Then to the global scope, so we can have cleaner step definitions.

It all works when I have cucumber-js option flags linking to a local file as cucumber-js --require ./test-preset.setup.js, however, once moving to the same preset over to an external module and requiring it as cucumber-js --require-module cucumber-preset-foo, the process ends with the same error presented at #1326.

I could spot something on the cli source code where supportCodeLibraryBuilder.reset is being called right after these external modules are required through supportCodeRequiredModules, which could make inviable interacting with the running cucumber instance once its data is being reset right after.

supportCodeRequiredModules.map((module) => require(module))
supportCodeLibraryBuilder.reset(this.cwd, newId)

reset(cwd: string, newId: IdGenerator.NewId): void {
this.cwd = cwd
this.newId = newId
this.afterTestCaseHookDefinitionConfigs = []
this.afterTestRunHookDefinitionConfigs = []
this.afterTestStepHookDefinitionConfigs = []
this.beforeTestCaseHookDefinitionConfigs = []
this.beforeTestRunHookDefinitionConfigs = []
this.beforeTestStepHookDefinitionConfigs = []
this.definitionFunctionWrapper = null
this.defaultTimeout = 5000
this.parameterTypeRegistry = new ParameterTypeRegistry()
this.stepDefinitionConfigs = []
this.World = World
}
}

Perhaps there's a specific reason for this design, however I would like to check if there would be any implication calling the reset method before requiring the modules, so we can make use of those portable presets? I can see this sort of feature benefiting some users who would like to use presets for specific development environments such as react e2e, for example.

node: v15.8.0
@cucumber/cucumber: 7.1.0
os: Linux
@aurelien-reeves
Copy link
Contributor

aurelien-reeves commented Apr 15, 2021

Hi @zanona

Your module looks interesting
Your investigation on that issue too

As you already have a good idea of what is happening and how it may be fixed, do you think you could open a PR for that, and to support the discussion around that?

@aurelien-reeves aurelien-reeves added the 🐛 bug Defect / Bug label Apr 15, 2021
@charlierudolph
Copy link
Member

Hmm, I don't see any issue with moving the reset to just before require-module. It being after was more a product of what require-module was used for in the past which had the primary use case of setting up transpilers (typescript / babel)

@zanona
Copy link
Author

zanona commented Apr 16, 2021

Sounds great guys.
I can surely prepare a PR, perhaps we can scope it as a feature rather than a bug, so I can prepare tests scoped to the user being able to create a custom preset and making sure the test runner understands it?

Alternatively, we could simply swap those two lines and watch for failed tests?

How would you prefer to go about it?

@aurelien-reeves
Copy link
Contributor

Regarding cucumber, this remain a bug as there is an unexpected error while trying to load a module in a regular way, that should actually work.

But you still can scope your PR as an enhancement with a scoped test as you described - I actually like the idea - which would have the benefit to fix that issue as well. What do you think?

Regarding the possibility to swap the two lines, that could be a first good starting point IMO :)

@aurelien-reeves aurelien-reeves added 🙏 help wanted Help wanted - not prioritized by core team ✅ accepted The core team has agreed that it is a good idea to fix this labels Apr 19, 2021
@davidjgoss davidjgoss self-assigned this Sep 24, 2021
@davidjgoss davidjgoss removed the 🙏 help wanted Help wanted - not prioritized by core team label Sep 24, 2021
@davidjgoss davidjgoss added this to the 8.0.0 milestone Dec 10, 2021
@davidjgoss
Copy link
Contributor

I don't see any issue with moving the reset to just before require-module.

I made this change under #1849 while I was in the area, so it will be out in the final 8.0.0 release - I'll close this for now but please open a fresh issue if this fails to solve your problem once it's available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug ✅ accepted The core team has agreed that it is a good idea to fix this
Projects
None yet
Development

No branches or pull requests

4 participants