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

Commit 7540c0d

Browse files
committed
Inject manifest
1 parent 373ab01 commit 7540c0d

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import test from "ava";
2+
import InlineChunkManifestHtmlWebpackPlugin from "../src/";
3+
4+
test.cb("inject manifest in head", t => {
5+
const manifestFilename = "a.manifest";
6+
const manifestFileContent = "source-content";
7+
const manifestVariable = "manifest-variable";
8+
9+
const compilationPluginEvent = (compilationEvent, alterAssets) => {
10+
if (compilationEvent === "html-webpack-plugin-alter-asset-tags") {
11+
const htmlPluginData = {
12+
head: []
13+
};
14+
15+
alterAssets(htmlPluginData, (_, result) => {
16+
t.is(result.head.length, 1);
17+
const asset = result.head[0];
18+
t.is(asset.tagName, "script");
19+
t.is(asset.closeTag, true);
20+
t.is(asset.attributes.type, "text/javascript");
21+
t.is(
22+
asset.innerHTML,
23+
`window.${manifestVariable}=${manifestFileContent}`
24+
);
25+
t.end();
26+
});
27+
}
28+
};
29+
30+
const pluginEvent = (compilerEvent, compile) => {
31+
t.is(compilerEvent, "compilation");
32+
33+
const assets = {};
34+
assets[manifestFilename] = {
35+
source: () => manifestFileContent
36+
};
37+
38+
const compilation = {
39+
plugin: compilationPluginEvent,
40+
assets: assets
41+
};
42+
43+
compile(compilation);
44+
};
45+
46+
const fakeCompiler = { plugin: pluginEvent };
47+
48+
const plugin = new InlineChunkManifestHtmlWebpackPlugin({
49+
filename: manifestFilename,
50+
manifestVariable: manifestVariable
51+
});
52+
53+
plugin.plugins = [{ apply: () => {} }];
54+
plugin.apply(fakeCompiler);
55+
});

0 commit comments

Comments
 (0)