Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ function getViewerData(bundleStats, bundleDir, opts) {
) {
const { children } = bundleStats;
[bundleStats] = bundleStats.children;
bundleStats.assets ||= [];
// Sometimes if there are additional child chunks produced add them as child assets,
// leave the 1st one as that is considered the 'root' asset.
for (let i = 1; i < children.length; i++) {
Expand Down
48 changes: 48 additions & 0 deletions test/analyzer-get-viewer-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const analyzer = require("../src/analyzer");

describe("getViewerData", () => {
it("handles child stats when the root child has no assets", () => {
const chartData = analyzer.getViewerData(
{
assets: [],
children: [
{
chunks: [],
modules: [],
},
{
assets: [
{
chunks: [1],
name: "child.js",
size: 12,
},
],
chunks: [
{
id: 1,
modules: [
{
chunks: [1],
id: 1,
identifier: "./child.js",
name: "./child.js",
size: 12,
},
],
},
],
},
],
},
null,
);

expect(chartData).toMatchObject([
{
label: "child.js",
statSize: 12,
},
]);
});
});