| 179 | ]; |
| 180 | |
| 181 | function runCompiler( |
| 182 | /** @type {(stats: import(class="st">"../types").StatsCompilation) => void} */ onSuccess, |
| 183 | /** @type {(err: Error) => void} */ onError |
| 184 | ) { |
| 185 | const c = webpack( |
| 186 | /** @type {import(class="st">"../types").Configuration} */ ( |
| 187 | /** @type {unknown} */ (options) |
| 188 | ) |
| 189 | ); |
| 190 | c.hooks.compilation.tap( |
| 191 | class="st">"CompilerCachingTest", |
| 192 | (compilation) => (compilation.bail = true) |
| 193 | ); |
| 194 | c.run((err, stats_) => { |
| 195 | if (err) throw err; |
| 196 | expect(typeof stats_).toBe(class="st">"object"); |
| 197 | const stats = /** @type {import(class="st">"../types").Stats} */ (stats_).toJson({ |
| 198 | modules: true, |
| 199 | reasons: true |
| 200 | }); |
| 201 | expect(typeof stats).toBe(class="st">"object"); |
| 202 | expect(stats).toHaveProperty(class="st">"errors"); |
| 203 | expect(Array.isArray(stats.errors)).toBe(true); |
| 204 | if (/** @type {unknown[]} */ (stats.errors).length > 0) { |
| 205 | onError(new Error(JSON.stringify(stats.errors, null, 4))); |
| 206 | } |
| 207 | c.close(() => { |
| 208 | onSuccess(stats); |
| 209 | }); |
| 210 | }); |
| 211 | } |
| 212 | |
| 213 | runCompiler(onSuccess, onError); |
| 214 | |