-
-
Notifications
You must be signed in to change notification settings - Fork 366
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
Add onDownloadProgress
option
#34
Conversation
I don't think What's the best tool for browser testing these days? Preferably something using Puppeteer. Probably https://github.com/direct-adv-interfaces/mocha-headless-chrome or https://github.com/mantoni/mochify.js // @sholladay |
I am aware of three high quality solutions for browser testing:
SitePen wrote a post about Puppeteer that is worth reading. For |
Sounds like Cypress would be the best fit then. I only care about testing it with Chromium. @dangdennis Would you be up for trying to integrate some Cypress tests? |
Thanks for the extensive thoughts @sholladay. I'll take this - I'll set up Cypress and a minimal test process. |
Awesome! Can you do it as a separate PR? Since there are other PRs that need it too, so it's not blocked by this PR. |
I'm a fan and use Cypress every day but I think it is overkill and not super well-suited for this. For unit tests like these, I would recommend Karmatic which wraps Puppeteer, Karma, and Jasmine. |
Hmm I've used Karma but never heard of Karmatic. It's emblematic of the problem that Karma has, though... it needs a layer on top of it to be manageable and useful. I do like the developer experience of a full Karma environment when it's properly set up, but this seems like it's just hiding the complexity. Some specific problems I see:
|
Sorry for the delay folks. This PR is blocked by the other Cypress PR to fulfill. That's being delayed by a bug within Cypress and Typescript (or something, I forget). Once that PR is merged, we can continue working on a method for end-to-end testing for the stream API. |
@sholladay If you think that is big 😄 But I am thankful that Cypress now uses a global cache. |
The Cypress install cache helps a lot, but I don't remember it ever taking that long to download. I will look into that more later. For now, here's a quick comparison that shows the caching in action. I am on slow Wi-Fi right now, so these numbers are rather extreme and should be taken with a grain of salt. But it's nonetheless a big difference. Cypress$ time npm install --save-dev cypress
> cypress@3.1.0 postinstall /private/tmp/foo/node_modules/cypress
> node index.js --exec install
Cypress 3.1.0 is already installed in /Users/sholladay/Library/Caches/Cypress/3.1.0
+ cypress@3.1.0
added 197 packages from 168 contributors and audited 327 packages in 4.615s
found 0 vulnerabilities
4.94 real 10.02 user 12.54 sys $ du -sh node_modules
51M node_modules Karmatic$ time npm install --save-dev karmatic
npm WARN deprecated karma-webpack@2.0.7: Deprecated due to publishing issue, use 2.0.8
npm WARN deprecated nodemailer@2.7.2: All versions below 4.0.1 of Nodemailer are deprecated. See https://nodemailer.com/status/
npm WARN deprecated node-uuid@1.4.8: Use uuid module instead
npm WARN deprecated hoek@2.16.3: The major version is no longer supported. Please update to 4.x or newer
npm WARN deprecated socks@1.1.9: If using 2.x branch, please upgrade to at least 2.1.6 to avoid a serious bug with socket data flow and an import issue introduced in 2.1.0
npm WARN deprecated mailcomposer@4.0.1: This project is unmaintained
npm WARN deprecated buildmail@4.0.1: This project is unmaintained
npm WARN deprecated uws@9.14.0: stop using this version
> fsevents@1.2.4 install /private/tmp/foo/node_modules/fsevents
> node install
[fsevents] Success: "/private/tmp/foo/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
> uws@9.14.0 install /private/tmp/foo/node_modules/uws
> node-gyp rebuild > build_log.txt 2>&1 || exit 0
> puppeteer@1.9.0 install /private/tmp/foo/node_modules/puppeteer
> node install.js
Downloading Chromium r594312 - 82.7 Mb [====================] 100% 0.0s
Chromium downloaded to /private/tmp/foo/node_modules/puppeteer/.local-chromium/mac-594312
> circular-json@0.5.8 postinstall /private/tmp/foo/node_modules/circular-json
> echo ''; echo -e "\x1B[1mCircularJSON\x1B[0m is in \x1B[4mmaintenance only\x1B[0m, \x1B[1mflatted\x1B[0m is its successor."; echo ''
-e CircularJSON is in maintenance only, flatted is its successor.
npm WARN karmatic@1.2.0 requires a peer of webpack@>=4 but none is installed. You must install peer dependencies yourself.
npm WARN babel-loader@7.1.5 requires a peer of webpack@2 || 3 || 4 but none is installed. You must install peer dependencies yourself.
npm WARN karma-webpack@2.0.7 requires a peer of webpack@^1.0.0 || ^2.0.0 || ^3.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN webpack-dev-middleware@1.12.2 requires a peer of webpack@^1.0.0 || ^2.0.0 || ^3.0.0 but none is installed. You must install peer dependencies yourself.
+ karmatic@1.2.0
added 668 packages from 729 contributors and audited 5735 packages in 386.563s
found 7 vulnerabilities (2 low, 5 moderate)
run `npm audit fix` to fix them, or `npm audit` for details
386.89 real 29.45 user 27.16 sys $ du -sh node_modules
265M node_modules 4.94 seconds vs 386.89 seconds (almost 6.5 minutes). Interestingly, Karmatic is 8MB smaller today. But on the other hand, look at all of those warnings and security vulnerabilities... leaves me with the impression they don't care about the dependency tree. |
@sholladay Cypress is not working though (#51) and it doesn't seem like they plan to do a new release anytime soon (last release was in August), so I would rather go for something that works now (Karmatic) than something that might work better in the future (Cypress). |
Sure, that makes sense enough. Anyone want to make that Karmatic PR? Then I'll add the stream test within here. |
We're now using Cypress, so this PR can be continued. |
@dangdennis I don't think we even need a const onProgress = stats => {
console.log(stats.percent, stats.bytesRead, stats.bytesTotal);
};
const res = await ky(someImageURL, {onProgress}).blob(); We need to make sure it still works fine with the retry feature. |
Can you also fix the merge conflict and rebase from master branch? |
If onProgress is passed, Ky will automatically stream the response. Unfortunately, @sindresorhus I still can't get the build to pass.
Also, I just fought with Git for an hour trying to squash my commits. So glad that's over with. However, I still haven't figured out how to fix merge conflicts and rebase without a commit. |
Probably because of https://github.com/sindresorhus/ky/pull/34/files#diff-cd87bb3712c5cc8ef9426451d8b99768L2 |
Also look at the diff, there are still many leftovers from the incorrect merge conflict resolving that needs to be fixed, like https://github.com/sindresorhus/ky/pull/34/files#diff-0730bb7c2e8f9ea2438b52e419dd86c9L121 |
a841491
to
ab8858a
Compare
I'm willing to help on this. If I can get write access to the fork, I'll work on tests and see what I can do about the diff and commit history. |
@sholladay That'd be helpful. Is that something @sindresorhus can enable? |
@szmarczak Thank you for taking this to completion - 6 month PR! |
Yes, it was sent 6 months ago. But it needed just a few days to complete :P |
@szmarczak #34 (comment) is not done. |
Oh, forgot about that. Will change. |
@szmarczak You also need to fix the merge conflict. |
Thanks all! 🙌 |
Here's the new PR for the potential stream API.
Basic example for reading an image stream:
Not sure how to test streams.
Fixes #3
Fixes #6