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
aws4fetch unusable in testing #28
Comments
Hey @James-Reed-cognito ! I don't really appreciate the title you've given this issue. There are tests in https://github.com/mhart/aws4fetch/tree/master/test – I assure you they work just fine. |
As the README says in the very first line, this library is:
If you need to get an environment like that working with jest, this looks like the right place to read up on: https://jestjs.io/docs/en/puppeteer Next time you're thinking of leaving an issue on a library that you want to use, especially if it's been created with people's free time and resources, just take a step back, take a breath, and have a think about whether it's really an issue with the library, or whether there are options you just haven't explored. Your open source experience will be all the better for it! |
Hey @mhart sorry for the prickly title - it was uncalled for. I'm used to a certain environment in which my unit tests for my webapps work, and in this environment, aws4fetch seemed to me to be unusable. Perhaps you could add something in the README that addresses this difference in aws4fetch specifically for testing, and that points to puppeteer or similar? Again, apologies for the curt tone in the title - please do feel free to change it (I looked but I can't seem to myself). |
The problem is you think it's an issue or difference with this library. It's not – this library is just using incredibly standard browser APIs. The issue is with the test runner you've chosen, and if you'd searched for how to get jest working with a browser you'd see it as the first result: |
The issue from my side was that I didn't know that all these errors were because of browser APIs - I've not seen TextEncoder before for example, so from my perspective it seemed like a load of strange errors. I did google around with searches like 'aws4fetch jest' and 'aws4fetch jest testing' and similar searches - I guess I didn't think to go a level up to the test runner. |
"TextEncoder jest" would've been a better search – you were on the right track with your "Jest runs in a node-like environment" hunch. Looks like there are issues with it: jestjs/jest#9983 and jsdom/jsdom#2524 In any case, all good. I'm not going to change the documentation – the first line makes it very clear what environment the library is intended for. It'd be like asking MDN to add documentation on how to get every browser API working with jest. That's just jest's responsibility (or jsdom's responsibility) to make sure they document what does and what doesn't work with their browser simulation. But I'm glad you're on the right track now 👍 Good luck! |
The first line does make it clear, but when I initially added this library to my project I wasn't thinking about testing, and my initial read of the README had gone out of my head - and when I tried to run my tests, getting what (to me) looked like esoteric errors lead me down wrong search paths and into confusion. A simple addition like Apologies again for the initial curt tone - I do appreciate the work people like you do for OSS and it's very easy for people like me to come in guns blazing. :) |
Hey there,
I found this library recently and was quite excited to try it out - everything worked perfectly for my app. However, when I tried to run tests using it, it seems to error out - presumably because Jest runs in a node-like environment, and aws4fetch expects a browser-like environment. The first error I got was that 'TextEncoder' was missing, and then when I got past that, that 'Request' was missing, and then 'crypto'...and then I stopped because having to essentially rebuild dependencies of a library isn't what I want to spend my time doing, and means that my tests aren't true to what's actually going on anyway.
This code:
Was what I started with (which would go as a arg to a
test
script ie"test": "jest --env=./__tests__/setup/jsdomSetup.js"
I'm not sure how other users of this library are getting around this, but not being able to run tests whilst using this library means it's a no-go, for now. I hope you can find some way of making it possible!
The text was updated successfully, but these errors were encountered: