Skip to content

Commit

Permalink
Also loop other test
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jan 4, 2022
1 parent 5e5361d commit 3cd60da
Showing 1 changed file with 77 additions and 73 deletions.
150 changes: 77 additions & 73 deletions test/watch/index.js
Expand Up @@ -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;
Expand Down

0 comments on commit 3cd60da

Please sign in to comment.