Skip to content

Commit

Permalink
Limit how long we wait at most
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jan 14, 2022
1 parent 898b94b commit 88aa452
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions test/cli/samples/watch/watch-config-early-update/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,33 @@ module.exports = {
configFile,
`
import { watch } from 'fs';
export default new Promise(resolve => {
const watcher = watch(${JSON.stringify(configFile)}, () => {
console.error('config update detected');
watcher.close();
setTimeout(() => {
console.error('resolve original config');
resolve({
input: 'main.js',
output: {
file: '_actual/output1.js',
format: 'es'
}
})
// wait a moment to make sure we do not trigger before Rollup's watcher
}, 600)
});
console.error('initial');
});
let watcher;
// Sometimes, fs.watch does not seem to trigger on MacOS. Thus, we wait at most 5 seconds.
export default Promise.race([
new Promise(resolve => {
watcher = watch(${JSON.stringify(configFile)}, () => {
console.error('config update detected');
watcher.close();
watcher = null;
// wait a moment to make sure we do not trigger before Rollup's watcher
setTimeout(resolve, 600);
})
}),
new Promise(resolve => setTimeout(() => {
if (watcher) {
watcher.close();
};
resolve();
}, 5000))
]).then(() => ({
input: 'main.js',
output: {
file: '_actual/output1.js',
format: 'es'
}
}));
console.error('initial');
`
);
return new Promise(resolve => setTimeout(resolve, 600));
Expand Down

0 comments on commit 88aa452

Please sign in to comment.