From a913d90a32f4c9cc7fc95175b45a41bd4f8c13bd 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 --- .../samples/watch/watch-config-early-update/_config.js | 8 ++++---- test/utils.js | 7 ++++--- 2 files changed, 8 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..e11cdc741f3 100644 --- a/test/cli/samples/watch/watch-config-early-update/_config.js +++ b/test/cli/samples/watch/watch-config-early-update/_config.js @@ -1,10 +1,11 @@ const fs = require('fs'); const path = require('path'); -const { syncFile } = require('../../../../utils'); +const { writeAndSync } = require('../../../../utils'); let configFile; module.exports = { + solo: true, description: 'immediately reloads the config file if a change happens while it is parsed', command: 'rollup -cw', before() { @@ -26,7 +27,7 @@ module.exports = { format: 'es' } }), - 3000 + 2000 ); });` ); @@ -36,7 +37,7 @@ module.exports = { }, abortOnStderr(data) { if (data === 'initial\n') { - fs.writeFileSync( + writeAndSync( configFile, ` console.error('updated'); @@ -49,7 +50,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); }