diff --git a/lib/index.ts b/lib/index.ts index f218f8d..7acf5ea 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -105,7 +105,7 @@ class PWMetrics { await sheets.appendResults(results.runs); } - this.outputData(results); + await this.outputData(results); if (this.flags.expectations) { const resultsToCompare = this.runs > 1 ? results.median.timings : results[0].timings; @@ -226,10 +226,10 @@ class PWMetrics { const formattedData = JSON.stringify(data, null, 2) + os.EOL; // output to file. if (this.flags.outputPath !== 'stdout') { - writeToDisk(this.flags.outputPath, formattedData); + return writeToDisk(this.flags.outputPath, formattedData); // output to stdout } else if (formattedData) { - process.stdout.write(formattedData); + return Promise.resolve(process.stdout.write(formattedData)); } } } diff --git a/lib/utils/fs.ts b/lib/utils/fs.ts index 60c9a06..acb8b06 100644 --- a/lib/utils/fs.ts +++ b/lib/utils/fs.ts @@ -3,6 +3,8 @@ import * as path from 'path'; import * as fs from 'fs'; +import * as promisify from 'micro-promisify'; + import {getMessageWithPrefix} from './messages'; import {Logger} from './logger'; @@ -27,11 +29,11 @@ export function getConfigFromFile(fileName: string = 'package.json') { } export function writeToDisk(fileName: string, data: string) { - return new Promise((resolve, reject) => { + return new Promise(async (resolve, reject) => { const filePath = path.join(process.cwd(), fileName); try { - fs.writeFileSync(filePath, data); + await promisify(fs.writeFile)(filePath, data); } catch (err) { reject(err); }