From 79cfb853b70785314241a28813dff6323c449415 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Tue, 8 Nov 2022 18:28:27 +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..cf91142c1fef 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, 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);