-
Notifications
You must be signed in to change notification settings - Fork 14
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
✨ Replace http and https with got #101
Conversation
77b5880
to
ebaccdf
Compare
package.json
Outdated
"htmlparser2": "3.9.2", | ||
"image-size": "0.5.1", | ||
"lodash": "4.17.4", |
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.
In sub dependencies/libraries we should always use the caret.
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.
See one line below, the lib required single lodash functions. Either we continue or you can remove the extra line.
lib/amperize.js
Outdated
var options = url.parse(element.attribs.src), | ||
timeout = 5000, | ||
request = element.attribs.src.indexOf('https') === 0 ? https : http; | ||
var imagePath = url.parse(element.attribs.src), |
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.
For readability: This is not a path, this is an object.
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.
Makes sense!
lib/amperize.js
Outdated
|
||
called = false; | ||
|
||
if (!validator.isURL(imagePath.href)) { | ||
if (called) return; |
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.
Why do we have to keep the called
variable?
I see three obvious cases:
- invalid url
- success
- error
Can you please explain?
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 wasn't sure if this is still needed when switching to got
. I removed it now, as got
should be able to handle it properly.
test/amperize.test.js
Outdated
@@ -310,7 +384,7 @@ describe('Amperize', function () { | |||
.get('/images/IMG_xyz.jpg') | |||
.socketDelay(5500) | |||
.reply(200, { | |||
data: '<Buffer 2c be a4 40 f7 87 73 1e 57 2c c1 e4 0d 79 03 95 42 f0 42 2e 41 95 27 c9 5c 35 a7 71 2c 09 5a 57 d3 04 1e 83 03 28 07 96 b0 c8 88 65 07 7a d1 d6 63 50>' | |||
body: '<Buffer 2c be a4 40 f7 87 73 1e 57 2c c1 e4 0d 79 03 95 42 f0 42 2e 41 95 27 c9 5c 35 a7 71 2c 09 5a 57 d3 04 1e 83 03 28 07 96 b0 c8 88 65 07 7a d1 d6 63 50>' |
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.
can handle timeout errors
If i run all tests locally, this test does not wait 5s, it finishes immediately.
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.
It's supposed to do so, afaik. We only pretend that there's a timeout.
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.
That does not make sense to me. How do we ensure the timeout works? 🤔
I guess you need to use .delay
and increase the test timeout with this.timeout
.
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.
Because the requested server returns a timeout error. This is what we mock.
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.
If we want to test, if got
library handles timeout, then we can use .delay
I think?
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.
Ok. Understood what you meant. I changed the test to simulate a real timeout with .delay
and this.timeout()
.
ebaccdf
to
71349aa
Compare
71349aa
to
b15df2f
Compare
b15df2f
to
f1ea202
Compare
closes jbhannah#99 - Used [`got`](https://github.com/sindresorhus/got) for image-size requests, which is more lightweight and has the huge advantage of following redirects - Added and updated test - indents - dercreased timeout to 3s instead of 5s - Added dependencies: - [validator](https://github.com/chriso/validator.js) - [lodash](https://github.com/lodash/lodash) - [got](https://github.com/sindresorhus/got)
f1ea202
to
c0f10c7
Compare
closes #99
got
for image-size requests, which is more lightweight and has the huge advantage of following redirects