From 207086180781e1daee52bcba0aefe3bed1b87b2e Mon Sep 17 00:00:00 2001 From: Marcin Strzyz <37447884+mastrzyz@users.noreply.github.com> Date: Sun, 23 Jul 2023 00:26:32 -0700 Subject: [PATCH] chore: ensure the file operations are async in the json reporter. (#24356) --- packages/playwright-test/src/reporters/json.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/playwright-test/src/reporters/json.ts b/packages/playwright-test/src/reporters/json.ts index f85427bb4f..6ba7d48801 100644 --- a/packages/playwright-test/src/reporters/json.ts +++ b/packages/playwright-test/src/reporters/json.ts @@ -55,7 +55,7 @@ class JSONReporter extends EmptyReporter { } override async onEnd(result: FullResult) { - outputReport(this._serializeReport(), this.config, this._outputFile); + await outputReport(this._serializeReport(), this.config, this._outputFile); } private _serializeReport(): JSONReport { @@ -222,13 +222,13 @@ class JSONReporter extends EmptyReporter { } } -function outputReport(report: JSONReport, config: FullConfig, outputFile: string | undefined) { +async function outputReport(report: JSONReport, config: FullConfig, outputFile: string | undefined) { const reportString = JSON.stringify(report, undefined, 2); if (outputFile) { assert(config.configFile || path.isAbsolute(outputFile), 'Expected fully resolved path if not using config file.'); outputFile = config.configFile ? path.resolve(path.dirname(config.configFile), outputFile) : outputFile; - fs.mkdirSync(path.dirname(outputFile), { recursive: true }); - fs.writeFileSync(outputFile, reportString); + await fs.promises.mkdir(path.dirname(outputFile), { recursive: true }); + await fs.promises.writeFile(outputFile, reportString); } else { console.log(reportString); }