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

fix: try require first for custom formatters so transpiled ones work #1985

Merged
merged 5 commits into from Apr 6, 2022

Conversation

davidjgoss
Copy link
Contributor

@davidjgoss davidjgoss commented Apr 4, 2022

🤔 What's changed?

Tweak the loading of custom formatters and snippet syntaxes so we try require() first and then try import() if it turns out the target file is a module (ESM).

This mirrors how we are also now loading the configuration file.

⚡️ What's your motivation?

https://cucumberbdd.slack.com/archives/C6QJ6N695/p1649071066867509

An edge case arguably, but some users in the wild have formatters in their project written in TypeScript (or something else that transpiles) and take advantage of the fact that --require-module means their transpiler has registered by the time the formatter is loaded.

This is quite cool and something we should avoid breaking if possible. We broke it with earlier RCs because we switched to exclusively using import() to load custom formatters, which doesn't yet account for just-in-time transpiled code.

In 1 or 2 major releases (when loader hooks are a solved problem) we'll ditch the require() bit and just use import() which will simplify things a lot but for now this works reliably and is well covered by tests.

🏷️ What kind of change is this?

  • 🐛 Bug fix (non-breaking change which fixes a defect)

📋 Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • Users should know about my change
    • I have added an entry to the "Unreleased" section of the CHANGELOG, linking to this pull request.

This text was originally generated from a template, then edited by hand. You can modify the template here.

@davidjgoss davidjgoss added this to the ESM milestone Apr 4, 2022
@coveralls
Copy link

coveralls commented Apr 4, 2022

Coverage Status

Coverage increased (+0.009%) to 98.232% when pulling fdedd7a on fix/custom-formatter-transpile into 901561e on main.

@davidjgoss davidjgoss changed the title Fix/custom formatter transpile fix: try require first for custom formatters so transpiled ones work Apr 4, 2022
Copy link
Contributor

@aurelien-reeves aurelien-reeves left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice!

Would it be hard to add a test (maybe a scenario?) that would help to make sure we were able to reproduce the error before the patch, and then validate the patch?

@davidjgoss
Copy link
Contributor Author

@aurelien-reeves thanks - several test in builder_spec.ts would fail without the code change here. I'll have a look at the feature tests too.

Copy link
Sponsor Contributor

@ludeknovy ludeknovy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix ❤️

Copy link
Contributor

@aurelien-reeves aurelien-reeves left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤩

@davidjgoss davidjgoss merged commit c97252d into main Apr 6, 2022
@davidjgoss davidjgoss deleted the fix/custom-formatter-transpile branch April 6, 2022 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants