Skip to content
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

Merged
merged 2 commits into from
Oct 3, 2017

Conversation

aileen
Copy link
Collaborator

@aileen aileen commented Sep 13, 2017

closes #99

  • Used got for image-size requests, which is more lightweight and has the huge advantage of following redirects
  • Added and updated test
  • indents
  • Added dependencies:

@coveralls
Copy link

coveralls commented Sep 13, 2017

Coverage Status

Coverage decreased (-1.8%) to 96.46% when pulling 9638035 on AileenCGN:use-got-and-follow-redirects into 94ac029 on jbhannah:master.

@aileen aileen force-pushed the use-got-and-follow-redirects branch 2 times, most recently from 77b5880 to ebaccdf Compare September 13, 2017 09:58
@coveralls
Copy link

coveralls commented Sep 13, 2017

Coverage Status

Coverage decreased (-0.02%) to 98.23% when pulling ebaccdf on AileenCGN:use-got-and-follow-redirects into 94ac029 on jbhannah:master.

@coveralls
Copy link

coveralls commented Sep 13, 2017

Coverage Status

Coverage decreased (-0.02%) to 98.23% when pulling ebaccdf on AileenCGN:use-got-and-follow-redirects into 94ac029 on jbhannah:master.

@aileen aileen mentioned this pull request Sep 19, 2017
4 tasks
package.json Outdated
"htmlparser2": "3.9.2",
"image-size": "0.5.1",
"lodash": "4.17.4",
Copy link
Collaborator

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.

Copy link
Collaborator

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),
Copy link
Collaborator

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.

Copy link
Collaborator Author

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;
Copy link
Collaborator

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:

  1. invalid url
  2. success
  3. error

Can you please explain?

Copy link
Collaborator Author

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.

@@ -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>'
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

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().

@aileen aileen force-pushed the use-got-and-follow-redirects branch from ebaccdf to 71349aa Compare October 3, 2017 08:33
@coveralls
Copy link

coveralls commented Oct 3, 2017

Coverage Status

Coverage decreased (-0.2%) to 98.095% when pulling 71349aa on AileenCGN:use-got-and-follow-redirects into 65d7037 on jbhannah:master.

@aileen aileen force-pushed the use-got-and-follow-redirects branch from 71349aa to b15df2f Compare October 3, 2017 09:03
@coveralls
Copy link

coveralls commented Oct 3, 2017

Coverage Status

Coverage decreased (-0.2%) to 98.095% when pulling b15df2f on AileenCGN:use-got-and-follow-redirects into 65d7037 on jbhannah:master.

@aileen aileen force-pushed the use-got-and-follow-redirects branch from b15df2f to f1ea202 Compare October 3, 2017 10:12
@coveralls
Copy link

coveralls commented Oct 3, 2017

Coverage Status

Coverage decreased (-0.2%) to 98.095% when pulling f1ea202 on AileenCGN:use-got-and-follow-redirects into 65d7037 on jbhannah:master.

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)
@aileen aileen force-pushed the use-got-and-follow-redirects branch from f1ea202 to c0f10c7 Compare October 3, 2017 10:36
@coveralls
Copy link

coveralls commented Oct 3, 2017

Coverage Status

Coverage decreased (-0.2%) to 98.095% when pulling c0f10c7 on AileenCGN:use-got-and-follow-redirects into 65d7037 on jbhannah:master.

@coveralls
Copy link

coveralls commented Oct 3, 2017

Coverage Status

Coverage increased (+1.8%) to 100.0% when pulling 49e9f89 on AileenCGN:use-got-and-follow-redirects into 65d7037 on jbhannah:master.

@kirrg001 kirrg001 merged commit b37c94a into jbhannah:master Oct 3, 2017
@aileen aileen deleted the use-got-and-follow-redirects branch May 10, 2018 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Follow redirects for images
3 participants