-
-
Notifications
You must be signed in to change notification settings - Fork 489
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
feat: add support to analyze gzipped bundles #379
base: master
Are you sure you want to change the base?
Changes from 2 commits
4988357
881a1ec
f2ad35a
9359ec1
5e0fbea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
const fs = require('fs'); | ||
const zlib = require('zlib'); | ||
|
||
const _ = require('lodash'); | ||
const {parseBundle} = require('../lib/parseUtils'); | ||
|
||
const BUNDLES_DIR = `${__dirname}/bundles`; | ||
const COMPRESSIONS = { | ||
brotli: {extension: 'br', algorithm: 'brotliDecompressSync'}, | ||
gzip: {extension: 'gz', algorithm: 'unzipSync'} | ||
}; | ||
|
||
describe('parseBundle', function () { | ||
const bundles = fs | ||
|
@@ -16,7 +21,7 @@ describe('parseBundle', function () { | |
.forEach(bundleName => { | ||
it(`should parse ${_.lowerCase(bundleName)}`, function () { | ||
const bundleFile = `${BUNDLES_DIR}/${bundleName}.js`; | ||
const bundle = parseBundle(bundleFile); | ||
const bundle = parseBundle(bundleFile, {}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Options parameter should be optional. |
||
const expectedModules = JSON.parse(fs.readFileSync(`${BUNDLES_DIR}/${bundleName}.modules.json`)); | ||
|
||
expect(bundle.src).to.equal(fs.readFileSync(bundleFile, 'utf8')); | ||
|
@@ -26,8 +31,29 @@ describe('parseBundle', function () { | |
|
||
it("should parse invalid bundle and return it's content and empty modules hash", function () { | ||
const bundleFile = `${BUNDLES_DIR}/invalidBundle.js`; | ||
const bundle = parseBundle(bundleFile); | ||
const bundle = parseBundle(bundleFile, {}); | ||
expect(bundle.src).to.equal(fs.readFileSync(bundleFile, 'utf8')); | ||
expect(bundle.modules).to.deep.equal({}); | ||
}); | ||
|
||
Object.keys(COMPRESSIONS) | ||
.forEach(compressionType => { | ||
it(`should parse compressed ${compressionType} bundle`, function () { | ||
const {extension, algorithm} = COMPRESSIONS[compressionType]; | ||
const bundleFile = `${BUNDLES_DIR}/validBundleWithArrowFunction.js`; | ||
const compressedBundleFile = `${bundleFile}.${extension}`; | ||
const expectedModules = JSON.parse(fs.readFileSync(`${BUNDLES_DIR}/validBundleWithArrowFunction.modules.json`)); | ||
if (!zlib[algorithm]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this condition - it swallows valid error and we won't notice it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For brotli, node version needs to be >= v11.7.0. Thus I put it to pass ci-checks which run on node 8. How do you suggest handling it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We need to mention it in the docs and properly handle in the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Check in tests, whether current version of Node supports it and expect successful decoding in one case and throwing of expected error in the other. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Brotli compression works for version >= v11.7.0, so it is kind of an already set expectation for brotli assets. Would you prefer it including in docs anyway? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Maybe compression is done with some external tool instead of Node.js. |
||
return; | ||
} | ||
const bundle = parseBundle(compressedBundleFile, { | ||
decompressExtenstion: { | ||
[extension]: {algorithm} | ||
} | ||
}); | ||
expect(bundle.src).to.equal(fs.readFileSync(bundleFile, 'utf8')); | ||
expect(bundle.modules).to.deep.equal(expectedModules.modules); | ||
}); | ||
}); | ||
|
||
}); |
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 don't think we need this option - decompression should be transparent to the end-user. It should just work without any configuration.
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 too agree on this, but then should it be basis extension itself, i.e. detect for
gz
/br
and apply respective decompression?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.
@th0r does the above comment look good?
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 so. We can think about customizable extensions if someone will raise an issue about it.