-
-
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
esm: add support for loaders #1844
Comments
@travi thanks for raising. I think it does make sense to add something, I'll aim to get something done for the next RC (though I note that loaders are still experimental in Node, so any support on our side would be experimental too). |
great! i'm happy to try it out and provide feedback
understood. i think that is important to keep visible, but is in line with how i've seen other projects handle the current state of things, so i don't expect that to present a problem for adoption |
Hello everyone, I'm hitting a massive wall with the ESM and CommonJS module loading. Here is a bit of background... I'm testing Angular application using Cucumber & Playwright. In order to do this I want to use Angular Material test harnesses which encapsulate the selectors and interaction into an API. I wrote the Playwright adapter for Angular Material harnesses and all was fine till Angular 13.... In Angular 13 they stopped distributing CommonJS build and only distribute ESM build and now the whole test suite fails because Cucumber-JS uses CommonJS imports but Angular only exports in ESM. From what I understand, if CucumberJS will load code using ESM all will work again because I can set my testsuite to compile (TS) to ESM, change my Playwright Adapter to ESM and load ESM Angular. Is there any viable / experimental branch I can give a shot and possibly help? I really need this to work and I'm more than happy to work on it. |
Did you tried v8.0.0-rc.2? Using esm code with it should work as-is. you may just have to rename a potential cucumber.js file into cucumber.cjs |
+1 to @aurelien-reeves comment above, please do give that a go
I think this might be where you hit a snag, if you are compiling TypeScript on the fly, because we don't have support for ESM loaders yet (which is what this issue is, I'll rename it for clarity). |
@davidjgoss & @aurelien-reeves I've now managed to run the whole thing on ESM modules. It has been pretty much rough ride but the Cucumber-JS was not really an issue. What I did is that at the moment I'm compiling the TypeScript code before running a test suite avoiding the TS-Node for now. Thanks for your work. |
Thanks for your feedback @pk |
this comment and following conversation appear to apply very directly to the situation here. linking here in case details of that conversation can help with understanding what a reasonable path forward might be in the short/long term. |
Just following up on this now I understand the state of loaders a bit better. ts-node and others support a However we should definitely aim to work when a loader has been registered with the process outside of Cucumber, and will work on that as a priority (with thanks to @travi for the detailed report and test repo). |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
With some testing with the newly-released 8.0.0 I found that:
Despite the inconsistency this seems like the right change - the vast majority of packages also have an extension for their bin files - and will be done via #1993 and released in 8.1.0 |
ts-node includes a workaround for the extensionless bin entrypoint issue. That might be why you don't see the issue with ts-node: |
@cspotcode ah yep there we go - thanks for the pointer! |
This has now been released in v8.1.0 on npm |
i've updated my test repo at https://github.com/travi-test/cucumber-esm/ with the latest version and it does solve the problem that this issue was specifically about. however, i'm now running into a different esm related problem:
this surprised me since you mentioned in #1993 that the fix was
i probably assumed too much and thought you saw tests passing, but i imagine that you were mostly checking that the previous error no longer occurred. @davidjgoss should i open a new issue for this, or is this just something minor that i'm overlooking on my end? |
Hey @travi - I think this will be down to a late change we made before 8.0.0 - #1931 - which means you need to explicitly use the |
Makes sense, thanks! I was wondering if the |
I'm incredibly happy to report that I've been able to upgrade our project to 8.1.2 and I can now run smoothly ESM, Angular 13, Playwright setup on top of ts-node with all steps/support code in TS. Thank you everyone. |
@pk glad on your results and maybe you can help ..that i'm also glad that this whole esm + ang 13 + playwright solution is working but I still do have 2 problems (not playwright or cucumber related) but maybe you can help Prob 2: when I import although having ts I have to provide the .js extension (in the login.page.ts: import { page } from '../support/hooks.js';) otherwise it does not work. Is it the same for you? I've found this: https://stackoverflow.com/questions/63807613/running-node-with-loader-ts-node-esm-js-requires-imports-to-have-the-js-extensi Here is my project: https://github.com/testgitdl/cucumber-playwright-ang13 |
Problem 2: I'm using
And this is my
Keep in mind my versions are: Cucumber 8.1.2, ts-node 10.7.0, typescript 4.6.3 & node gives me v18. |
@testgitdl As for Problem 1, yes that's still valid on my setup as well. I'm using relative paths... at the moment. |
@pk thanks for helping out. I've made the setup as you stated and it is still not working but what I did not manage to do is to run the script as you mentioned: "test": "NODE_OPTIONS="--loader ts-node/esm --no-warnings --experimental-specifier-resolution=node" cucumber-js" If I change to: "test": "SET NODE_OPTIONS="--loader ts-node/esm --no-warnings --experimental-specifier-resolution=node" && cucumber-js",
|
@testgitdl Careful with the (") quotes.... You need to escape internal quotes with \ (slash). This is scripts part of my
I run this using: I've also just run my test suite on the CI with Node v16.13.0 successfully. |
@pk indeed with the quotes and the slash before (copied from from your comment above |
@testgitdl I won't be much of help with Windows, sorry. What if you set the "global" env variable and then try to run the test suite. On Mac I'd do something like this in terminal:
|
@pk no problem! thanks for your help! And to debug in VS Code:
|
@pk managed to remove the relative paths by using a workaround..a custom loader specified here TypeStrong/ts-node#1450 (comment) On windows now I'm able to use the paths when running Cucumber+Playwright+Angular13 tests via: Where loader.js: const { absoluteBaseUrl, paths } = tsConfigPaths.loadConfig() export function resolve(specifier, ctx, defaultResolve) { export { load, transformSource } from 'ts-node/esm'` Hope it helps |
Linking to the PR that will add built-in path mapping to ts-node: TypeStrong/ts-node#1664 |
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
I'm excited to start migrating projects of mine that are tested with cucumber over to native ESM. However, as mentioned in #1304 (comment), loaders do not appear to work with the recent release candidate. I'm unsure if this is intended to work at this point, but I wasnt able to figure it out on my own.
instead, i meet the following error:
Describe the solution you'd like
A clear and concise description of what you want to happen.
ideally, the
cucumber-js
binary would accept--loader=<loader-name>
directlyDescribe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
an alternative that should work is providing the loader through
NODE_OPTIONS
, likeNODE_OPTIONS="--loader=testdouble" cucumber-js ...
Additional context
Add any other context or screenshots about the feature request here.
As requested in #1304 (comment), I've created a fairly minimal reproducible example at https://github.com/travi-test/cucumber-esm/.
The error can be demonstrated by running
npm run test:integration
(afternpm install
, of course). If the--loader=testdouble
is removed from thetest:integration:base
script, the error goes away. In this minimal example that results in the tests passing because I'm not actually using the loader.In a more realistic project, this obviously results in the loader not working, resulting in failures. An example of a more real project can be found in the
cucumber-esm
branch of https://github.com/pragmatic-divops/cli where I'm attempting to begin the process of converting the project to ESM.The text was updated successfully, but these errors were encountered: