|
1 | 1 | import path from "path";
|
2 | 2 |
|
3 | 3 | import postcss from "postcss";
|
4 |
| -import { NormalModule } from "webpack"; |
5 | 4 |
|
6 | 5 | import {
|
7 | 6 | compile,
|
@@ -84,47 +83,51 @@ describe("loader", () => {
|
84 | 83 |
|
85 | 84 | it('should register dependencies using the "messages" API', async () => {
|
86 | 85 | const plugin = () => (css, result) => {
|
87 |
| - result.messages.push({ |
88 |
| - type: "build-dependency", |
89 |
| - file: "build-dep.html", |
90 |
| - content: "", |
91 |
| - plugin, |
92 |
| - }); |
| 86 | + result.messages.push( |
| 87 | + { |
| 88 | + type: "build-dependency", |
| 89 | + file: path.resolve(__dirname, "fixtures", "build-dep.html"), |
| 90 | + content: "", |
| 91 | + plugin, |
| 92 | + }, |
| 93 | + { |
| 94 | + type: "missing-dependency", |
| 95 | + file: path.resolve(__dirname, "fixtures", "missing-dep.html"), |
| 96 | + content: "", |
| 97 | + plugin, |
| 98 | + }, |
| 99 | + { |
| 100 | + type: "context-dependency", |
| 101 | + file: path.resolve(__dirname, "fixtures", "deps"), |
| 102 | + content: "", |
| 103 | + plugin, |
| 104 | + } |
| 105 | + ); |
93 | 106 | };
|
94 | 107 |
|
95 |
| - let actualBuildInfo = null; |
96 |
| - |
97 | 108 | const postcssPlugin = postcss.plugin("postcss-plugin", plugin);
|
98 |
| - const compiler = getCompiler( |
99 |
| - "./css/index.js", |
100 |
| - { |
101 |
| - postcssOptions: { |
102 |
| - plugins: [postcssPlugin()], |
103 |
| - }, |
| 109 | + const compiler = getCompiler("./css/index.js", { |
| 110 | + postcssOptions: { |
| 111 | + plugins: [postcssPlugin()], |
104 | 112 | },
|
105 |
| - { |
106 |
| - plugins: [ |
107 |
| - { |
108 |
| - /** @param {import("webpack").Compiler} compiler */ |
109 |
| - apply(wpcompiler) { |
110 |
| - wpcompiler.hooks.compilation.tap("plugin", (compilation) => { |
111 |
| - NormalModule.getCompilationHooks(compilation).beforeLoaders.tap( |
112 |
| - "plugin", |
113 |
| - (_1, module) => { |
114 |
| - actualBuildInfo = module.buildInfo; |
115 |
| - } |
116 |
| - ); |
117 |
| - }); |
118 |
| - }, |
119 |
| - }, |
120 |
| - ], |
121 |
| - } |
122 |
| - ); |
| 113 | + }); |
123 | 114 |
|
124 | 115 | const stats = await compile(compiler);
|
125 |
| - |
126 |
| - const buildDependencies = [...actualBuildInfo.buildDependencies]; |
127 |
| - expect(buildDependencies).toContain("build-dep.html"); |
| 116 | + const { |
| 117 | + contextDependencies, |
| 118 | + missingDependencies, |
| 119 | + buildDependencies, |
| 120 | + } = stats.compilation; |
| 121 | + |
| 122 | + expect(contextDependencies).toContain( |
| 123 | + path.resolve(__dirname, "fixtures", "deps") |
| 124 | + ); |
| 125 | + expect(missingDependencies).toContain( |
| 126 | + path.resolve(__dirname, "fixtures", "missing-dep.html") |
| 127 | + ); |
| 128 | + expect(buildDependencies).toContain( |
| 129 | + path.resolve(__dirname, "fixtures", "build-dep.html") |
| 130 | + ); |
128 | 131 |
|
129 | 132 | expect(getWarnings(stats)).toMatchSnapshot("warnings");
|
130 | 133 | expect(getErrors(stats)).toMatchSnapshot("errors");
|
|
0 commit comments