diff --git a/test/watch/index.js b/test/watch/index.js index 39037c43048..329aee62ebe 100644 --- a/test/watch/index.js +++ b/test/watch/index.js @@ -314,81 +314,85 @@ describe('rollup.watch', () => { } } - it('correctly rewrites change event during build delay', async () => { - const WATCHED_ID = path.resolve('test/_tmp/input/watched'); - const MAIN_ID = path.resolve('test/_tmp/input/main.js'); - let lastEvent = null; - await sander.copydir('test/watch/samples/watch-files').to('test/_tmp/input'); - await wait(100); - watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', - output: { - file: 'test/_tmp/output/bundle.js', - format: 'cjs', - exports: 'auto' - }, - watch: { - buildDelay: 600, - chokidar: { - atomic: false - } - }, - plugins: { - buildStart() { - this.addWatchFile(WATCHED_ID); - }, - watchChange(id, { event }) { - if (id === WATCHED_ID) { - assert.strictEqual(lastEvent, null); - lastEvent = event; + { + for (let pass = 1; pass <= 10; pass++) { + it('correctly rewrites change event during build delay' + pass, async () => { + const WATCHED_ID = path.resolve('test/_tmp/input/watched'); + const MAIN_ID = path.resolve('test/_tmp/input/main.js'); + let lastEvent = null; + await sander.copydir('test/watch/samples/watch-files').to('test/_tmp/input'); + await wait(100); + watcher = rollup.watch({ + input: 'test/_tmp/input/main.js', + output: { + file: 'test/_tmp/output/bundle.js', + format: 'cjs', + exports: 'auto' + }, + watch: { + buildDelay: 600, + chokidar: { + atomic: false + } + }, + plugins: { + buildStart() { + this.addWatchFile(WATCHED_ID); + }, + watchChange(id, { event }) { + if (id === WATCHED_ID) { + assert.strictEqual(lastEvent, null); + lastEvent = event; + } + } } - } - } - }); + }); - return sequence(watcher, [ - 'START', - 'BUNDLE_START', - 'BUNDLE_END', - 'END', - async () => { - assert.strictEqual(lastEvent, null); - atomicWriteFileSync(WATCHED_ID, 'another'); - await wait(100); - sander.unlinkSync(WATCHED_ID); - }, - 'START', - 'BUNDLE_START', - 'BUNDLE_END', - 'END', - async () => { - assert.strictEqual(lastEvent, 'delete'); - lastEvent = null; - atomicWriteFileSync(WATCHED_ID, '123'); - await wait(100); - sander.unlinkSync(WATCHED_ID); - // To ensure there is always another change to trigger a rebuild - atomicWriteFileSync(MAIN_ID, 'export default 43;'); - }, - 'START', - 'BUNDLE_START', - 'BUNDLE_END', - 'END', - async () => { - assert.strictEqual(lastEvent, null); - atomicWriteFileSync(WATCHED_ID, '123'); - await wait(100); - atomicWriteFileSync(WATCHED_ID, 'asd'); - }, - 'START', - 'BUNDLE_START', - 'BUNDLE_END', - 'END', - () => { - assert.strictEqual(lastEvent, 'create'); - } - ]); - }).timeout(20000); + return sequence(watcher, [ + 'START', + 'BUNDLE_START', + 'BUNDLE_END', + 'END', + async () => { + assert.strictEqual(lastEvent, null); + atomicWriteFileSync(WATCHED_ID, 'another'); + await wait(100); + sander.unlinkSync(WATCHED_ID); + }, + 'START', + 'BUNDLE_START', + 'BUNDLE_END', + 'END', + async () => { + assert.strictEqual(lastEvent, 'delete'); + lastEvent = null; + atomicWriteFileSync(WATCHED_ID, '123'); + await wait(100); + sander.unlinkSync(WATCHED_ID); + // To ensure there is always another change to trigger a rebuild + atomicWriteFileSync(MAIN_ID, 'export default 43;'); + }, + 'START', + 'BUNDLE_START', + 'BUNDLE_END', + 'END', + async () => { + assert.strictEqual(lastEvent, null); + atomicWriteFileSync(WATCHED_ID, '123'); + await wait(100); + atomicWriteFileSync(WATCHED_ID, 'asd'); + }, + 'START', + 'BUNDLE_START', + 'BUNDLE_END', + 'END', + () => { + assert.strictEqual(lastEvent, 'create'); + } + ]); + }).timeout(20000); + } + } it('calls closeWatcher plugin hook', () => { let calls = 0;