* @param {import("../").Configuration} options options * @returns {Promise<{ errors: import("../").StatsError[], warnings: import("../").StatsError[] }>} errors and warnings
(options)
| 141 | * @returns {Promise<{ errors: import(class="st">"../").StatsError[], warnings: import(class="st">"../").StatsError[] }>} errors and warnings |
| 142 | */ |
| 143 | async function compile(options) { |
| 144 | const stats = await new Promise((resolve, reject) => { |
| 145 | const compiler = webpack( |
| 146 | /** @type {import(class="st">"../").Configuration} */ ({ |
| 147 | ...defaults.options, |
| 148 | ...options |
| 149 | }) |
| 150 | ); |
| 151 | if (options.mode === class="st">"production") { |
| 152 | if (options.optimization) options.optimization.minimize = true; |
| 153 | else options.optimization = { minimize: true }; |
| 154 | } |
| 155 | compiler.outputFileSystem = defaults.outputFileSystem; |
| 156 | |
| 157 | try { |
| 158 | compiler.run((bailedError, stats) => { |
| 159 | if (bailedError) { |
| 160 | return reject(bailedError); |
| 161 | } |
| 162 | compiler.close((closeError) => { |
| 163 | if (closeError) { |
| 164 | return reject(closeError); |
| 165 | } |
| 166 | resolve(stats); |
| 167 | }); |
| 168 | }); |
| 169 | } catch (err) { |
| 170 | class="cm">// capture sync thrown errors |
| 171 | reject(err); |
| 172 | } |
| 173 | }); |
| 174 | |
| 175 | expect(typeof stats).toBe(class="st">"object"); |
| 176 | const statsResult = stats.toJson({ errorDetails: false }); |
| 177 | expect(typeof statsResult).toBe(class="st">"object"); |
| 178 | const { errors, warnings } = statsResult; |
| 179 | expect(Array.isArray(errors)).toBe(true); |
| 180 | expect(Array.isArray(warnings)).toBe(true); |
| 181 | |
| 182 | return { errors, warnings }; |
| 183 | } |
| 184 | |
| 185 | expectNoDeprecations(); |
| 186 |