Skip to content

Commit

Permalink
Add watcher to test
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jan 5, 2022
1 parent 4d445ee commit 009ced5
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions test/cli/samples/watch/watch-config-early-update/_config.js
Expand Up @@ -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');
});
`
);
Expand Down

0 comments on commit 009ced5

Please sign in to comment.