From bd5e924b77e7bc4b0474fbbb180c87315a816eac Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Tue, 4 Jan 2022 07:13:13 +0100 Subject: [PATCH] Repeat change event test --- test/watch/index.js | 144 +++++++++++++++++++++++--------------------- 1 file changed, 74 insertions(+), 70 deletions(-) diff --git a/test/watch/index.js b/test/watch/index.js index 76a957fb634..bf785c92669 100644 --- a/test/watch/index.js +++ b/test/watch/index.js @@ -235,77 +235,81 @@ describe('rollup.watch', () => { ]); }); - it('passes change parameter to the watchChange plugin hook', async () => { - const WATCHED_ID = path.resolve('test/_tmp/input/watched'); - const events = []; - let ids; - const expectedIds = [WATCHED_ID, path.resolve('test/_tmp/input/main.js')]; - await sander.copydir('test/watch/samples/watch-files').to('test/_tmp/input'); - await sander.unlink(WATCHED_ID); - await wait(100); - watcher = rollup.watch({ - input: 'test/_tmp/input/main.js', - output: { - file: 'test/_tmp/output/bundle.js', - format: 'cjs', - exports: 'auto' - }, - plugins: { - buildStart() { - this.addWatchFile(WATCHED_ID); - }, - watchChange(id, { event }) { - assert.strictEqual(id, WATCHED_ID); - events.push(event); - }, - buildEnd() { - ids = this.getWatchFiles(); - } - } - }); + { + for (let pass = 1; pass <= 10; pass++) { + it('passes change parameter to the watchChange plugin hook' + pass, async () => { + const WATCHED_ID = path.resolve('test/_tmp/input/watched'); + const events = []; + let ids; + const expectedIds = [WATCHED_ID, path.resolve('test/_tmp/input/main.js')]; + await sander.copydir('test/watch/samples/watch-files').to('test/_tmp/input'); + await sander.unlink(WATCHED_ID); + await wait(100); + watcher = rollup.watch({ + input: 'test/_tmp/input/main.js', + output: { + file: 'test/_tmp/output/bundle.js', + format: 'cjs', + exports: 'auto' + }, + plugins: { + buildStart() { + this.addWatchFile(WATCHED_ID); + }, + watchChange(id, { event }) { + assert.strictEqual(id, WATCHED_ID); + events.push(event); + }, + buildEnd() { + ids = this.getWatchFiles(); + } + } + }); - return sequence(watcher, [ - 'START', - 'BUNDLE_START', - 'BUNDLE_END', - 'END', - () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); - assert.deepStrictEqual(events, []); - assert.deepStrictEqual(ids, expectedIds); - atomicWriteFileSync(WATCHED_ID, 'first'); - }, - 'START', - 'BUNDLE_START', - 'BUNDLE_END', - 'END', - () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); - assert.deepStrictEqual(events, ['create']); - assert.deepStrictEqual(ids, expectedIds); - atomicWriteFileSync(WATCHED_ID, 'first'); - }, - 'START', - 'BUNDLE_START', - 'BUNDLE_END', - 'END', - () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); - assert.deepStrictEqual(events, ['create', 'update']); - assert.deepStrictEqual(ids, expectedIds); - sander.unlinkSync(WATCHED_ID); - }, - 'START', - 'BUNDLE_START', - 'BUNDLE_END', - 'END', - () => { - assert.strictEqual(run('../_tmp/output/bundle.js'), 42); - assert.deepStrictEqual(events, ['create', 'update', 'delete']); - assert.deepStrictEqual(ids, expectedIds); - } - ]); - }); + return sequence(watcher, [ + 'START', + 'BUNDLE_START', + 'BUNDLE_END', + 'END', + () => { + assert.strictEqual(run('../_tmp/output/bundle.js'), 42); + assert.deepStrictEqual(events, []); + assert.deepStrictEqual(ids, expectedIds); + atomicWriteFileSync(WATCHED_ID, 'first'); + }, + 'START', + 'BUNDLE_START', + 'BUNDLE_END', + 'END', + () => { + assert.strictEqual(run('../_tmp/output/bundle.js'), 42); + assert.deepStrictEqual(events, ['create']); + assert.deepStrictEqual(ids, expectedIds); + atomicWriteFileSync(WATCHED_ID, 'first'); + }, + 'START', + 'BUNDLE_START', + 'BUNDLE_END', + 'END', + () => { + assert.strictEqual(run('../_tmp/output/bundle.js'), 42); + assert.deepStrictEqual(events, ['create', 'update']); + assert.deepStrictEqual(ids, expectedIds); + sander.unlinkSync(WATCHED_ID); + }, + 'START', + 'BUNDLE_START', + 'BUNDLE_END', + 'END', + () => { + assert.strictEqual(run('../_tmp/output/bundle.js'), 42); + assert.deepStrictEqual(events, ['create', 'update', 'delete']); + assert.deepStrictEqual(ids, expectedIds); + } + ]); + }); + } + } it('correctly rewrites change event during build delay', async () => { const WATCHED_ID = path.resolve('test/_tmp/input/watched');