-
-
Notifications
You must be signed in to change notification settings - Fork 381
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
|
||
const contentRes = handleRangeHeaders(content, req, res); | ||
expect(contentRes).toEqual('abcdef'); | ||
expect(res.statusCode).toBeUndefined(); |
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.
@evilebottnawi Is this expected behavior that the statusCode is not set to something on malformed range header?
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.
We need looks in docs/specs, i think statusCode should always be
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 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(); |
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.
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); | |||
}); |
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.
@evilebottnawi I think a 200 response code is fine since we are intentionally ignoring these header cases.
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.
Agree
@@ -1,6 +1,6 @@ | |||
import parseRange from 'range-parser'; | |||
|
|||
export default function handleRangeHeaders(content, req, res) { | |||
export default function handleRangeHeaders(context, content, req, res) { |
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.
Made a breaking change here because I think context should come first
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.
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.' |
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.
@evilebottnawi Logging it now as an error and proceeding with a normal response
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.
Good job!
This PR contains a:
Motivation / Use-Case
Adding tests for util files
Breaking Changes
Yes, breaking API change for handleRangeHeaders util
Additional Info