From 68f8830b70b0212785d7f0689238b4f19292f6dd Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sun, 9 Jan 2022 09:09:21 +0100 Subject: [PATCH] Improve test reliability --- .../cli/samples/watch/watch-config-early-update/_config.js | 7 +++---- test/utils.js | 7 ++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/cli/samples/watch/watch-config-early-update/_config.js b/test/cli/samples/watch/watch-config-early-update/_config.js index 08b5799f33c..02e3884aa4d 100644 --- a/test/cli/samples/watch/watch-config-early-update/_config.js +++ b/test/cli/samples/watch/watch-config-early-update/_config.js @@ -1,6 +1,6 @@ const fs = require('fs'); const path = require('path'); -const { syncFile } = require('../../../../utils'); +const { writeAndSync } = require('../../../../utils'); let configFile; @@ -26,7 +26,7 @@ module.exports = { format: 'es' } }), - 3000 + 2000 ); });` ); @@ -36,7 +36,7 @@ module.exports = { }, abortOnStderr(data) { if (data === 'initial\n') { - fs.writeFileSync( + writeAndSync( configFile, ` console.error('updated'); @@ -49,7 +49,6 @@ module.exports = { }; ` ); - syncFile(configFile); return false; } if (data.includes(`created _actual${path.sep}output2.js`)) { diff --git a/test/utils.js b/test/utils.js index bebb306b5c6..7bd767d5751 100644 --- a/test/utils.js +++ b/test/utils.js @@ -16,7 +16,7 @@ exports.assertDirectoriesAreEqual = assertDirectoriesAreEqual; exports.assertFilesAreEqual = assertFilesAreEqual; exports.assertIncludes = assertIncludes; exports.atomicWriteFileSync = atomicWriteFileSync; -exports.syncFile = syncFile; +exports.writeAndSync = writeAndSync; exports.getFileNamesAndRemoveOutput = getFileNamesAndRemoveOutput; function normaliseError(error) { @@ -235,8 +235,9 @@ function atomicWriteFileSync(filePath, contents) { } // It appears that on MacOS, it sometimes takes long for the file system to update -function syncFile(filePath) { - const file = fs.openSync(filePath); +function writeAndSync(filePath, contents) { + const file = fs.openSync(filePath, 'w'); + fs.writeSync(file, contents); fs.fsyncSync(file); fs.closeSync(file); }