Skip to content

chore(utils): add utils tests #675

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

Merged
merged 9 commits into from
Jul 14, 2020
Merged

Conversation

knagaitsev
Copy link
Contributor

@knagaitsev knagaitsev commented Jul 9, 2020

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

Adding tests for util files

Breaking Changes

Yes, breaking API change for handleRangeHeaders util

Additional Info

@codecov
Copy link

codecov bot commented Jul 9, 2020

Codecov Report

Merging #675 into master will increase coverage by 0.44%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #675      +/-   ##
==========================================
+ Coverage   99.12%   99.56%   +0.44%     
==========================================
  Files           9        9              
  Lines         228      231       +3     
  Branches       70       71       +1     
==========================================
+ Hits          226      230       +4     
+ Misses          2        1       -1     
Impacted Files Coverage Δ
src/middleware.js 100.00% <100.00%> (ø)
src/utils/handleRangeHeaders.js 100.00% <100.00%> (ø)
src/utils/setupWriteToDisk.js 100.00% <0.00%> (+2.56%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6afd559...bc36405. Read the comment docs.


const contentRes = handleRangeHeaders(content, req, res);
expect(contentRes).toEqual('abcdef');
expect(res.statusCode).toBeUndefined();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evilebottnawi Is this expected behavior that the statusCode is not set to something on malformed range header?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need looks in docs/specs, i think statusCode should always be

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is ok to ignore malformed range, log error in console and return original code, i.e. 200 if no problems before


const contentRes = handleRangeHeaders(content, req, res);
expect(contentRes).toEqual('abcdef');
expect(res.statusCode).toBeUndefined();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@@ -229,6 +229,17 @@ describe('middleware', () => {
.expect(206, done);
});

it('should return the "200" code for the "GET" request with malformed range header which is ignored', (done) => {
request(app).get('/bundle.js').set('Range', 'abc').expect(200, done);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evilebottnawi I think a 200 response code is fine since we are intentionally ignoring these header cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

@knagaitsev knagaitsev changed the title WIP: add utils tests chore(utils): add utils tests Jul 11, 2020
@knagaitsev
Copy link
Contributor Author

/cc @evilebottnawi @hiroppy

@@ -1,6 +1,6 @@
import parseRange from 'range-parser';

export default function handleRangeHeaders(content, req, res) {
export default function handleRangeHeaders(context, content, req, res) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a breaking change here because I think context should come first

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All is fine, we are in rc

} else if (ranges.length !== 1) {
// multiple ranges treated as regular response
context.logger.error(
'A Range header with multiple ranges was provided. Multiple ranges are not supported, so a regular response will be sent for this request.'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evilebottnawi Logging it now as an error and proceeding with a normal response

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

@hiroppy hiroppy merged commit 86c308c into webpack:master Jul 14, 2020
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.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy