-
Notifications
You must be signed in to change notification settings - Fork 57
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
Browser: Add fetch for urls #54
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.
@DanMHammer Cool, another nice improvement! 🎖️
test/browser-fixtures.test.js
Outdated
@@ -139,6 +140,28 @@ describe('PDFMerger', () => { | |||
expect(diff).toBeFalsy() | |||
}) | |||
|
|||
test('merge pdfs from urls', async () => { |
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.
Could you please add some Tests to also test ArrayBuffer
, Blob
, data-url
and some invalifd inputs like strings that are no valid urls and maybe even some nonsence-input like numbers and objects, to test the error-path!? Thx!
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.
- Added tests for ArrayBuffer and Buffer.
- Added a mock fetch function since node-fetch and isomorphic-fetch both cause open handle issues with jest, apparently. All of their documentation and SO threads I could find say to just mock fetch instead.
- Added tests for mock Blobs
- Cannot test dataurls or blob urls as those are browser only. jsdom does not currently support simulating them and has no plan to.
73b0e48
to
563bcda
Compare
@DanMHammer Thx! 🏅 I contacted @nbesli about giving you access to this project. You are now definitely one of the main contributors! Could you please contact me so that I have an email-adress of you. Thx! |
I consider this a breaking change because the browser "add" function is now |
|
||
fileReader.readAsArrayBuffer(inputFile) | ||
fileReader.onload = function (evt) { | ||
return fileReader.result |
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.
I think this PR broke the FileReader
implementation, at least from looking at the code. This return doesn't do anything, because it's an anonymous function. The outer _getInputFile
never gets the result and I think it will reach the throw
at the bottom?
You can return new Promise(...)
that was originally wrapping the whole thing just for this branch
Maybe also reject
onerror
, currently silently ignored
Summary
Changes to pdf-merger-js/browser:
http
,https
,about
,blob
,data
, orfile
). See: fetch documentationinputFile
Changes to browser-fixtures-test:
Closing Comments
This should allow pdf-merger-js/browser to be more convenient to use. #51 created the browser version to be feature comparable to the non-browser version, but this adds an additional helpful feature that is simple to implement and use due to the native fetch api.
See: #17