@@ -67,6 +67,28 @@ type QaEvidenceEntryStatus = {
|
67 | 67 | }; |
68 | 68 | }; |
69 | 69 | |
| 70 | +async function readQaSuiteSummaryFile(summaryPath: string): Promise<unknown> { |
| 71 | +let summaryText: string; |
| 72 | +try { |
| 73 | +summaryText = await fs.readFile(summaryPath, "utf8"); |
| 74 | +} catch (error) { |
| 75 | +throw new QaSuiteArtifactError( |
| 76 | +"summary_read_failed", |
| 77 | +`Could not read QA summary JSON at ${summaryPath}: ${formatErrorMessage(error)}`, |
| 78 | +{ cause: error }, |
| 79 | +); |
| 80 | +} |
| 81 | +try { |
| 82 | +return JSON.parse(summaryText) as unknown; |
| 83 | +} catch (error) { |
| 84 | +throw new QaSuiteArtifactError( |
| 85 | +"summary_parse_failed", |
| 86 | +`Could not parse QA summary JSON at ${summaryPath}: ${formatErrorMessage(error)}`, |
| 87 | +{ cause: error }, |
| 88 | +); |
| 89 | +} |
| 90 | +} |
| 91 | + |
70 | 92 | function readNonNegativeCount(value: unknown): number | null { |
71 | 93 | return typeof value === "number" && Number.isFinite(value) |
72 | 94 | ? Math.max(0, Math.floor(value)) |
@@ -176,26 +198,7 @@ export function readQaSuiteFailedOrSkippedScenarioCountFromSummary(
|
176 | 198 | } |
177 | 199 | |
178 | 200 | export async function readQaSuiteFailedScenarioCountFromFile(summaryPath: string): Promise<number> { |
179 | | -let summaryText: string; |
180 | | -try { |
181 | | -summaryText = await fs.readFile(summaryPath, "utf8"); |
182 | | -} catch (error) { |
183 | | -throw new QaSuiteArtifactError( |
184 | | -"summary_read_failed", |
185 | | -`Could not read QA summary JSON at ${summaryPath}: ${formatErrorMessage(error)}`, |
186 | | -{ cause: error }, |
187 | | -); |
188 | | -} |
189 | | -let payload: unknown; |
190 | | -try { |
191 | | -payload = JSON.parse(summaryText) as unknown; |
192 | | -} catch (error) { |
193 | | -throw new QaSuiteArtifactError( |
194 | | -"summary_parse_failed", |
195 | | -`Could not parse QA summary JSON at ${summaryPath}: ${formatErrorMessage(error)}`, |
196 | | -{ cause: error }, |
197 | | -); |
198 | | -} |
| 201 | +const payload = await readQaSuiteSummaryFile(summaryPath); |
199 | 202 | const failedScenarioCount = readQaSuiteFailedScenarioCountFromSummary(payload); |
200 | 203 | if (failedScenarioCount !== null) { |
201 | 204 | return failedScenarioCount; |
@@ -209,26 +212,7 @@ export async function readQaSuiteFailedScenarioCountFromFile(summaryPath: string
|
209 | 212 | export async function readQaSuiteFailedOrSkippedScenarioCountFromFile( |
210 | 213 | summaryPath: string, |
211 | 214 | ): Promise<number> { |
212 | | -let summaryText: string; |
213 | | -try { |
214 | | -summaryText = await fs.readFile(summaryPath, "utf8"); |
215 | | -} catch (error) { |
216 | | -throw new QaSuiteArtifactError( |
217 | | -"summary_read_failed", |
218 | | -`Could not read QA summary JSON at ${summaryPath}: ${formatErrorMessage(error)}`, |
219 | | -{ cause: error }, |
220 | | -); |
221 | | -} |
222 | | -let payload: unknown; |
223 | | -try { |
224 | | -payload = JSON.parse(summaryText) as unknown; |
225 | | -} catch (error) { |
226 | | -throw new QaSuiteArtifactError( |
227 | | -"summary_parse_failed", |
228 | | -`Could not parse QA summary JSON at ${summaryPath}: ${formatErrorMessage(error)}`, |
229 | | -{ cause: error }, |
230 | | -); |
231 | | -} |
| 215 | +const payload = await readQaSuiteSummaryFile(summaryPath); |
232 | 216 | const blockingScenarioCount = readQaSuiteFailedOrSkippedScenarioCountFromSummary(payload); |
233 | 217 | if (blockingScenarioCount !== null) { |
234 | 218 | return blockingScenarioCount; |
|