Skip to content
This repository was archived by the owner on Jun 8, 2022. It is now read-only.

Commit 5dad9ee

Browse files
committed
Ensure output chunk filename is reset
1 parent 321909e commit 5dad9ee

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import test from "ava";
2+
3+
import ChunkManifestPlugin from "../src/chunk-manifest-webpack-plugin";
4+
5+
test.cb("generate asset for chunk manifest", t => {
6+
const chunkFilename = "[filename]";
7+
8+
const chunk = {
9+
id: 1,
10+
hasRuntime: () => true,
11+
chunks: []
12+
};
13+
14+
const thisCompilationPluginEvent = (compilationEvent, ensure) => {
15+
if (compilationEvent === "require-ensure") {
16+
const outputOptions = { chunkFilename };
17+
18+
ensure.apply({ outputOptions }, [undefined, chunk]);
19+
20+
t.is(outputOptions.chunkFilename, "__CHUNK_MANIFEST__");
21+
}
22+
};
23+
24+
const compilationPluginEvent = (compilationEvent, ensure) => {
25+
if (compilationEvent === "require-ensure") {
26+
const outputOptions = { chunkFilename: "overwrite-this" };
27+
28+
ensure.apply({ outputOptions }, ["", chunk]);
29+
30+
t.is(outputOptions.chunkFilename, chunkFilename);
31+
t.end();
32+
}
33+
};
34+
35+
const pluginEvent = (event, compile) => {
36+
const compilation = {
37+
mainTemplate: {
38+
plugin: undefined
39+
},
40+
assets: {}
41+
};
42+
43+
if (event === "this-compilation") {
44+
compilation.mainTemplate.plugin = thisCompilationPluginEvent;
45+
compile(compilation);
46+
}
47+
48+
if (event === "compilation") {
49+
compilation.mainTemplate.plugin = compilationPluginEvent;
50+
compile(compilation);
51+
}
52+
};
53+
54+
const fakeCompiler = { plugin: pluginEvent };
55+
56+
const plugin = new ChunkManifestPlugin();
57+
58+
plugin.apply(fakeCompiler);
59+
});

0 commit comments

Comments
 (0)