Repository navigation
test: assert compression with Cache-Control lacking no-transform - #294
Open
renanmpimentel wants to merge 1 commit into
Open
renanmpimentel wants to merge 1 commit into
renanmpimentel wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Adds a test block next to the existing
Cache-Control: no-transformtests asserting that a response is still compressed when it has aCache-Controlheader that does not containno-transform(no-cacheandpublic, max-age=60).Why
The
Cache-Controltests only cover the negative side ofshouldTransform(): every case sets a value containingno-transformand asserts that the response is not compressed. Nothing checks the positive side, so a regression that disables compression for any response carryingCache-Controlgoes unnoticed.For example, either of these changes to
shouldTransform()inindex.jsleaves the whole suite green (63 passing):That would silently stop compressing a very common class of responses, including the Server-Sent Events example in the README, which sets
Cache-Control: no-cacheand relies on compression +res.flush().Verification
npm test: 65 passing, 1 pending (was 63 passing, 1 pending)npm run lint: no issuesBefore / after against the regression above (
||→&&inshouldTransform):expected "Content-Encoding" header fieldThe second variant (
return !cacheControl) gives the same result.I found this while experimenting with Supertest (unrelated to the
supertestHTTP library), a tool for evaluating test effectiveness using mutation testing and test-harness mutilation.