From d995cdf4c738c7b43c25a857c9a43ac9b5988442 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 5 Jan 2022 06:48:40 +0100 Subject: [PATCH] Add watcher to test --- .../watch-config-early-update/_config.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 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..3f99ca919e3 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 - ); + }), 600) + }); + console.error('initial'); }); ` );