Skip to content

Commit

Permalink
Flush atomic file writes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jan 9, 2022
1 parent 2026631 commit 6ea5894
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/cli/samples/watch/watch-config-early-update/_config.js
@@ -1,6 +1,6 @@
const fs = require('fs');
const path = require('path');
const { atomicWriteFileSync } = require('../../../../utils');
const { atomicWriteFileSync, syncFile } = require('../../../../utils');

let configFile;

Expand Down Expand Up @@ -49,6 +49,7 @@ module.exports = {
};
`
);
syncFile(configFile);
return false;
}
if (data.includes(`created _actual${path.sep}output2.js`)) {
Expand Down
8 changes: 8 additions & 0 deletions test/utils.js
Expand Up @@ -16,6 +16,7 @@ exports.assertDirectoriesAreEqual = assertDirectoriesAreEqual;
exports.assertFilesAreEqual = assertFilesAreEqual;
exports.assertIncludes = assertIncludes;
exports.atomicWriteFileSync = atomicWriteFileSync;
exports.syncFile = syncFile;
exports.getFileNamesAndRemoveOutput = getFileNamesAndRemoveOutput;

function normaliseError(error) {
Expand Down Expand Up @@ -232,3 +233,10 @@ function atomicWriteFileSync(filePath, contents) {
fs.writeFileSync(stagingPath, contents);
fs.renameSync(stagingPath, filePath);
}

// It appears that on MacOS, it sometimes takes long for the file system to update
function syncFile(filePath) {
const file = fs.openSync(filePath);
fs.fsyncSync(file);
fs.closeSync(file);
}

0 comments on commit 6ea5894

Please sign in to comment.