This repository was archived by the owner on Sep 7, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathappLoad.test.js
More file actions
77 lines (69 loc) · 2.38 KB
/
Copy pathappLoad.test.js
File metadata and controls
77 lines (69 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Checks that reading a stats file survives the parts a stats file is allowed
// to leave out (webpack/analyse#34). Run with `npm test`.
var test = require("node:test");
var assert = require("node:assert");
var app = require("../app/app");
function load(stats) {
// Loading reports to google analytics, which falls back to console.log
// outside the browser.
var log = console.log;
console.log = function() {};
try {
app.load(stats);
} finally {
console.log = log;
}
return app.stats;
}
function module_(id, chunks) {
return {
id: id,
identifier: "/m" + id + ".js",
name: "./m" + id + ".js",
size: 100,
chunks: chunks
};
}
test("reads a stats file written with chunks: false", function() {
// webpack leaves the chunks out but still names them on every module,
// which is what used to throw on "parents of undefined".
var stats = load({
modules: [module_(1, [0]), module_(2, [1])]
});
assert.deepStrictEqual(stats.chunks, []);
assert.deepStrictEqual(stats.modules[0].chunks, [0], "the ids are kept");
assert.strictEqual(app.mapChunks[0], undefined, "and lead nowhere");
});
test("survives a chunk whose parent is not in the file", function() {
var stats = load({
modules: [module_(1, [1])],
chunks: [
{ id: 1, size: 100, parents: [7], names: ["main"], files: ["main.js"] }
]
});
assert.deepStrictEqual(stats.chunks[0].children, [], "nothing to link to");
assert.deepStrictEqual(stats.chunks[0].parents, [7], "the id is kept");
});
test("fills in the chunk fields a stats file can omit", function() {
var stats = load({ modules: [], chunks: [{ id: 0, size: 10 }] });
var chunk = stats.chunks[0];
assert.deepStrictEqual(chunk.parents, []);
assert.deepStrictEqual(chunk.origins, []);
assert.deepStrictEqual(chunk.names, []);
assert.deepStrictEqual(chunk.files, []);
assert.deepStrictEqual(chunk.children, []);
});
test("fills in the module fields a stats file can omit", function() {
var stats = load({
modules: [{ id: 1, identifier: "/m1.js", name: "./m1.js", size: 100 }]
});
assert.deepStrictEqual(stats.modules[0].chunks, []);
assert.deepStrictEqual(stats.modules[0].reasons, []);
assert.deepStrictEqual(stats.modules[0].dependencies, []);
});
test("reads a stats file with nothing in it at all", function() {
var stats = load({});
assert.deepStrictEqual(stats.modules, []);
assert.deepStrictEqual(stats.chunks, []);
assert.deepStrictEqual(stats.assets, []);
});