|
| 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