Skip to content

Commit

Permalink
test: added
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Apr 10, 2024
1 parent dcb5ade commit 667bd16
Show file tree
Hide file tree
Showing 3 changed files with 318 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function getViewerData(bundleStats, bundleDir, opts) {
});
}

// Picking only `*.js or *.mjs` assets from bundle that has non-empty `chunks` array
// Picking only `*.js, *.cjs or *.mjs` assets from bundle that has non-empty `chunks` array
bundleStats.assets = bundleStats.assets.filter(asset => {
// Filter out non 'asset' type asset if type is provided (Webpack 5 add a type to indicate asset types)
if (asset.type && asset.type !== 'asset') {
Expand Down
5 changes: 5 additions & 0 deletions test/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ describe('Analyzer', function () {
await expectValidReport({bundleLabel: 'bundle.mjs'});
});

it('should support stats files with cjs chunk', async function () {
generateReportFrom('with-cjs-chunk.json');
await expectValidReport({bundleLabel: 'bundle.cjs'});
});

it('should properly parse extremely optimized bundle from webpack 5', async function () {
generateReportFrom('extremely-optimized-webpack-5-bundle/stats.json');
const chartData = await getChartData();
Expand Down
312 changes: 312 additions & 0 deletions test/stats/with-cjs-chunk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,312 @@
{
"errors": [],
"warnings": [],
"version": "1.14.0",
"hash": "4e39ab22a848116a4c15",
"children": [
{
"errors": [],
"warnings": [],
"version": "1.14.0",
"hash": "4e39ab22a848116a4c15",
"time": 79,
"publicPath": "",
"assetsByChunkName": {
"bundle": "bundle.cjs"
},
"assets": [
{
"name": "bundle.cjs",
"size": 1735,
"chunks": [0],
"chunkNames": ["bundle"],
"emitted": true
}
],
"chunks": [
{
"id": 0,
"rendered": true,
"initial": true,
"entry": true,
"extraAsync": false,
"size": 141,
"names": ["bundle"],
"files": ["bundle.cjs"],
"hash": "eb0091314b5c4ca75abf",
"parents": [],
"modules": [
{
"id": 0,
"identifier": "/Volumes/Work/webpack-bundle-analyzer/test/src/index.js",
"name": "./src/index.js",
"index": 0,
"index2": 3,
"size": 54,
"cacheable": true,
"built": true,
"optional": false,
"prefetched": false,
"chunks": [0],
"assets": [],
"issuer": null,
"profile": {
"factory": 19,
"building": 15
},
"failed": false,
"errors": 0,
"warnings": 0,
"reasons": [],
"source": "require('./a');\nrequire('./b');\nrequire('./a-clone');\n"
},
{
"id": 1,
"identifier": "/Volumes/Work/webpack-bundle-analyzer/test/src/a.js",
"name": "./src/a.js",
"index": 1,
"index2": 0,
"size": 29,
"cacheable": true,
"built": true,
"optional": false,
"prefetched": false,
"chunks": [0],
"assets": [],
"issuer": "/Volumes/Work/webpack-bundle-analyzer/test/src/index.js",
"profile": {
"factory": 8,
"building": 6
},
"failed": false,
"errors": 0,
"warnings": 0,
"reasons": [
{
"moduleId": 0,
"moduleIdentifier": "/Volumes/Work/webpack-bundle-analyzer/test/src/index.js",
"module": "./src/index.js",
"moduleName": "./src/index.js",
"type": "cjs require",
"userRequest": "./a",
"loc": "1:0-14"
}
],
"source": "module.exports = 'module a';\n"
},
{
"id": 2,
"identifier": "/Volumes/Work/webpack-bundle-analyzer/test/src/b.js",
"name": "./src/b.js",
"index": 2,
"index2": 1,
"size": 29,
"cacheable": true,
"built": true,
"optional": false,
"prefetched": false,
"chunks": [0],
"assets": [],
"issuer": "/Volumes/Work/webpack-bundle-analyzer/test/src/index.js",
"profile": {
"factory": 9,
"building": 5
},
"failed": false,
"errors": 0,
"warnings": 0,
"reasons": [
{
"moduleId": 0,
"moduleIdentifier": "/Volumes/Work/webpack-bundle-analyzer/test/src/index.js",
"module": "./src/index.js",
"moduleName": "./src/index.js",
"type": "cjs require",
"userRequest": "./b",
"loc": "2:0-14"
}
],
"source": "module.exports = 'module b';\n"
},
{
"id": 3,
"identifier": "/Volumes/Work/webpack-bundle-analyzer/test/src/a-clone.js",
"name": "./src/a-clone.js",
"index": 3,
"index2": 2,
"size": 29,
"cacheable": true,
"built": true,
"optional": false,
"prefetched": false,
"chunks": [0],
"assets": [],
"issuer": "/Volumes/Work/webpack-bundle-analyzer/test/src/index.js",
"profile": {
"factory": 10,
"building": 5
},
"failed": false,
"errors": 0,
"warnings": 0,
"reasons": [
{
"moduleId": 0,
"moduleIdentifier": "/Volumes/Work/webpack-bundle-analyzer/test/src/index.js",
"module": "./src/index.js",
"moduleName": "./src/index.js",
"type": "cjs require",
"userRequest": "./a-clone",
"loc": "3:0-20"
}
],
"source": "module.exports = 'module a';\n"
}
],
"filteredModules": 0,
"origins": [
{
"moduleId": 0,
"module": "/Volumes/Work/webpack-bundle-analyzer/test/src/index.js",
"moduleIdentifier": "/Volumes/Work/webpack-bundle-analyzer/test/src/index.js",
"moduleName": "./src/index.js",
"loc": "",
"name": "bundle",
"reasons": []
}
]
}
],
"modules": [
{
"id": 0,
"identifier": "/Volumes/Work/webpack-bundle-analyzer/test/src/index.js",
"name": "./src/index.js",
"index": 0,
"index2": 3,
"size": 54,
"cacheable": true,
"built": true,
"optional": false,
"prefetched": false,
"chunks": [0],
"assets": [],
"issuer": null,
"profile": {
"factory": 19,
"building": 15
},
"failed": false,
"errors": 0,
"warnings": 0,
"reasons": [],
"source": "require('./a');\nrequire('./b');\nrequire('./a-clone');\n"
},
{
"id": 1,
"identifier": "/Volumes/Work/webpack-bundle-analyzer/test/src/a.js",
"name": "./src/a.js",
"index": 1,
"index2": 0,
"size": 29,
"cacheable": true,
"built": true,
"optional": false,
"prefetched": false,
"chunks": [0],
"assets": [],
"issuer": "/Volumes/Work/webpack-bundle-analyzer/test/src/index.js",
"profile": {
"factory": 8,
"building": 6
},
"failed": false,
"errors": 0,
"warnings": 0,
"reasons": [
{
"moduleId": 0,
"moduleIdentifier": "/Volumes/Work/webpack-bundle-analyzer/test/src/index.js",
"module": "./src/index.js",
"moduleName": "./src/index.js",
"type": "cjs require",
"userRequest": "./a",
"loc": "1:0-14"
}
],
"source": "module.exports = 'module a';\n"
},
{
"id": 2,
"identifier": "/Volumes/Work/webpack-bundle-analyzer/test/src/b.js",
"name": "./src/b.js",
"index": 2,
"index2": 1,
"size": 29,
"cacheable": true,
"built": true,
"optional": false,
"prefetched": false,
"chunks": [0],
"assets": [],
"issuer": "/Volumes/Work/webpack-bundle-analyzer/test/src/index.js",
"profile": {
"factory": 9,
"building": 5
},
"failed": false,
"errors": 0,
"warnings": 0,
"reasons": [
{
"moduleId": 0,
"moduleIdentifier": "/Volumes/Work/webpack-bundle-analyzer/test/src/index.js",
"module": "./src/index.js",
"moduleName": "./src/index.js",
"type": "cjs require",
"userRequest": "./b",
"loc": "2:0-14"
}
],
"source": "module.exports = 'module b';\n"
},
{
"id": 3,
"identifier": "/Volumes/Work/webpack-bundle-analyzer/test/src/a-clone.js",
"name": "./src/a-clone.js",
"index": 3,
"index2": 2,
"size": 29,
"cacheable": true,
"built": true,
"optional": false,
"prefetched": false,
"chunks": [0],
"assets": [],
"issuer": "/Volumes/Work/webpack-bundle-analyzer/test/src/index.js",
"profile": {
"factory": 10,
"building": 5
},
"failed": false,
"errors": 0,
"warnings": 0,
"reasons": [
{
"moduleId": 0,
"moduleIdentifier": "/Volumes/Work/webpack-bundle-analyzer/test/src/index.js",
"module": "./src/index.js",
"moduleName": "./src/index.js",
"type": "cjs require",
"userRequest": "./a-clone",
"loc": "3:0-20"
}
],
"source": "module.exports = 'module a';\n"
}
],
"filteredModules": 0,
"children": []
}
]
}

0 comments on commit 667bd16

Please sign in to comment.