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 7451c2f3492..ad46e9c1e7a 100644 --- a/test/cli/samples/watch/watch-config-early-update/_config.js +++ b/test/cli/samples/watch/watch-config-early-update/_config.js @@ -9,24 +9,29 @@ module.exports = { description: 'immediately reloads the config file if a change happens while it is parsed', command: 'rollup -cw', before() { + // This test writes a config file that watches itself for changes and resolves only once it has + // been rewritten. As soon as that watcher is set up, the config file writes a message to stderr + // that is observed by the parent process and triggers overwriting the config file. + // That way, we reliably simulate a complicated config file being changed while it is parsed. fs.mkdirSync(path.resolve(__dirname, '_actual')); configFile = path.resolve(__dirname, 'rollup.config.js'); fs.writeFileSync( configFile, ` - console.error('initial'); + import chokidar from 'chokidar'; export default new Promise(resolve => { - setTimeout( - () => - resolve({ + const watcher = chokidar.watch(${JSON.stringify(configFile)}) + .on('change', () => { + watcher.close(); + setTimeout(() => resolve({ input: { output1: 'main.js' }, output: { dir: '_actual', format: 'es' } - }), - 1000 - ); + }), 300) + }); + console.error('initial'); }); ` );