-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
There was a problem hiding this 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?
@aurelien-reeves thanks - several test in |
There was a problem hiding this 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 ❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤩
🤔 What's changed?
Tweak the loading of custom formatters and snippet syntaxes so we try
require()
first and then tryimport()
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 useimport()
which will simplify things a lot but for now this works reliably and is well covered by tests.🏷️ What kind of change is this?
📋 Checklist:
This text was originally generated from a template, then edited by hand. You can modify the template here.