Skip to content

Commit

Permalink
Improve test reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jan 9, 2022
1 parent 5498cd7 commit 68f8830
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
7 changes: 3 additions & 4 deletions 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;

Expand All @@ -26,7 +26,7 @@ module.exports = {
format: 'es'
}
}),
3000
2000
);
});`
);
Expand All @@ -36,7 +36,7 @@ module.exports = {
},
abortOnStderr(data) {
if (data === 'initial\n') {
fs.writeFileSync(
writeAndSync(
configFile,
`
console.error('updated');
Expand All @@ -49,7 +49,6 @@ module.exports = {
};
`
);
syncFile(configFile);
return false;
}
if (data.includes(`created _actual${path.sep}output2.js`)) {
Expand Down
7 changes: 4 additions & 3 deletions test/utils.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

0 comments on commit 68f8830

Please sign in to comment.