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 a913d90
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions 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() {
Expand All @@ -26,7 +27,7 @@ module.exports = {
format: 'es'
}
}),
3000
2000
);
});`
);
Expand All @@ -36,7 +37,7 @@ module.exports = {
},
abortOnStderr(data) {
if (data === 'initial\n') {
fs.writeFileSync(
writeAndSync(
configFile,
`
console.error('updated');
Expand All @@ -49,7 +50,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 a913d90

Please sign in to comment.