Cucumber-js: allow cucumber-preset modules under require-module

Created on 13 Apr 2021  路  4Comments  路  Source: cucumber/cucumber-js

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.

https://github.com/cucumber/cucumber-js/blob/e2fd32a4fe411484275307e2a4b59605a8ded165/src/cli/index.ts#L160-L161

https://github.com/cucumber/cucumber-js/blob/e2fd32a4fe411484275307e2a4b59605a8ded165/src/support_code_library_builder/index.ts#L402-L417

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
bug help wanted accepted

All 4 comments

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?

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)

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?

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 :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lamartire picture lamartire  路  6Comments

edwinwright picture edwinwright  路  3Comments

jechazelle picture jechazelle  路  5Comments

hdorgeval picture hdorgeval  路  3Comments

jfstephe picture jfstephe  路  4Comments