* @param {Record<string, unknown> | ((stats: CachingStats, files: Record<string, string>, iteration: number) => void)} options run options or callback * @param {((stats: CachingStats, files: Record<string, string>, iteration: number) => void)=} callback done callback
(options, callback)
| 100 | * @param {((stats: CachingStats, files: Record<string, string>, iteration: number) => void)=} callback done callback |
| 101 | */ |
| 102 | function runCompiler(options, callback) { |
| 103 | if (typeof options === "function") { |
| 104 | callback = options; |
| 105 | options = {}; |
| 106 | } |
| 107 | c.run((err, rawStats) => { |
| 108 | if (err) throw err; |
| 109 | expect(typeof rawStats).toBe("object"); |
| 110 | const stats = /** @type {CachingStats} */ ( |
| 111 | /** @type {import("../").Stats} */ (rawStats).toJson({ |
| 112 | modules: true, |
| 113 | reasons: true |
| 114 | }) |
| 115 | ); |
| 116 | expect(typeof stats).toBe("object"); |
| 117 | expect(stats).toHaveProperty("errors"); |
| 118 | expect(Array.isArray(stats.errors)).toBe(true); |
| 119 | if (/** @type {Record<string, unknown>} */ (options).expectErrors) { |
| 120 | expect(stats.errors).toHaveLength( |
| 121 | /** @type {number} */ ( |
| 122 | /** @type {Record<string, unknown>} */ (options).expectErrors |
| 123 | ) |
| 124 | ); |
| 125 | } else if (stats.errors && stats.errors.length > 0) { |
| 126 | expect(typeof stats.errors[0]).toBe("string"); |
| 127 | throw new Error( |
| 128 | /** @type {string} */ (/** @type {unknown} */ (stats.errors[0])) |
| 129 | ); |
| 130 | } |
| 131 | stats.logs = logs; |
| 132 | /** @type {(stats: CachingStats, files: Record<string, string>, iteration: number) => void} */ ( |
| 133 | callback |
| 134 | )(stats, files, compilerIteration++); |
| 135 | }); |
| 136 | } |
| 137 | |
| 138 | runCompiler(callback); |
| 139 |