-
-
Notifications
You must be signed in to change notification settings - Fork 499
feat: add support to analyze gzipped bundles #379
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
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, {}); | ||
|
||
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]) { | ||
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.