From fb80cf4a11b62e3a930107bd025aaf48af3b3345 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Tue, 8 Nov 2022 16:52:46 +0100 Subject: [PATCH] task: turn file checks into async --- scripts/task.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/task.ts b/scripts/task.ts index 183f9bfd48d6..03e84043089a 100644 --- a/scripts/task.ts +++ b/scripts/task.ts @@ -1,7 +1,7 @@ /* eslint-disable no-await-in-loop */ import type { AbortController } from 'node-abort-controller'; import { getJunitXml } from 'junit-xml'; -import { outputFile, existsSync, readFile } from 'fs-extra'; +import { outputFile, existsSync, readFile, pathExists } from 'fs-extra'; import { join, resolve } from 'path'; import { prompt } from 'prompts'; import boxen from 'boxen'; @@ -279,14 +279,15 @@ async function runTask(task: Task, details: TemplateDetails, optionValues: Passe return controller; } catch (err) { + const hasJunitFile = await pathExists(junitFilename); // If there's a non-test related error (junit report has not been reported already), we report the general failure in a junit report - if (junitFilename && !existsSync(junitFilename)) { + if (junitFilename && !hasJunitFile) { await writeJunitXml(getTaskKey(task), details.key, startTime, err); } throw err; } finally { - if (existsSync(junitFilename)) { + if (await pathExists(junitFilename)) { const junitXml = await (await readFile(junitFilename)).toString(); const prefixedXml = junitXml.replace(/classname="(.*)"/g, `classname="${details.key} $1"`); await outputFile(junitFilename, prefixedXml);