Skip to content

Commit

Permalink
Fix watch tests on Mac
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed May 10, 2020
1 parent c6c2532 commit 6d6a180
Showing 1 changed file with 63 additions and 56 deletions.
119 changes: 63 additions & 56 deletions test/watch/index.js
Expand Up @@ -32,7 +32,7 @@ describe('rollup.watch', () => {
return require(resolved);
}

function sequence(watcher, events) {
function sequence(watcher, events, timeout = 300) {
return new Promise((fulfil, reject) => {
function go(event) {
const next = events.shift();
Expand All @@ -52,7 +52,7 @@ describe('rollup.watch', () => {
});
} else {
Promise.resolve()
.then(() => wait(100)) // gah, this appears to be necessary to fix random errors
.then(() => wait(timeout)) // gah, this appears to be necessary to fix random errors
.then(() => next(event))
.then(go)
.catch(error => {
Expand Down Expand Up @@ -196,8 +196,8 @@ describe('rollup.watch', () => {
'BUNDLE_END',
'END',
() => {
watchChangeCnt = 0;
assert.strictEqual(run('../_tmp/output/bundle.js'), 42);
assert.strictEqual(watchChangeCnt, 0);
sander.writeFileSync('test/_tmp/input/main.js', 'export default 43;');
},
'START',
Expand Down Expand Up @@ -1003,8 +1003,8 @@ describe('rollup.watch', () => {
'BUNDLE_END',
'END',
() => {
watchChangeCnt = 0;
assert.strictEqual(sander.existsSync('../_tmp/output/bundle.js'), false);
assert.strictEqual(watchChangeCnt, 0);
sander.writeFileSync('test/_tmp/input/main.js', 'export default 43;');
},
'START',
Expand Down Expand Up @@ -1050,63 +1050,70 @@ describe('rollup.watch', () => {
});

let startTime;
return sequence(watcher, [
'START',
'BUNDLE_START',
'BUNDLE_END',
'END',
() => {
assert.strictEqual(run('../_tmp/output/bundle.js'), 42);
sander.writeFileSync('test/_tmp/input/main.js', 'export default 43;');
startTime = process.hrtime();
},
'START',
'BUNDLE_START',
'BUNDLE_END',
'END',
() => {
assert.strictEqual(run('../_tmp/output/bundle.js'), 43);
const timeDiff = getTimeDiffInMs(startTime);
assert.ok(timeDiff < 400, `Time difference ${timeDiff} < 400`);
}
]);
return sequence(
watcher,
[
'START',
'BUNDLE_START',
'BUNDLE_END',
'END',
() => {
assert.strictEqual(run('../_tmp/output/bundle.js'), 42);
sander.writeFileSync('test/_tmp/input/main.js', 'export default 43;');
startTime = process.hrtime();
},
'START',
'BUNDLE_START',
'BUNDLE_END',
'END',
() => {
assert.strictEqual(run('../_tmp/output/bundle.js'), 43);
const timeDiff = getTimeDiffInMs(startTime);
assert.ok(timeDiff < 400, `Time difference ${timeDiff} < 400`);
}
],
0
);
});

it('observes configured build delays', async () => {
await sander.copydir('test/watch/samples/basic').to('test/_tmp/input');
watcher = rollup.watch([
{
input: 'test/_tmp/input/main.js',
output: {
file: 'test/_tmp/output/bundle.js',
format: 'cjs'
}
},
{
input: 'test/_tmp/input/main.js',
watch: { clearScreen: true },
output: {
file: 'test/_tmp/output/bundle.js',
format: 'cjs'
}
},
{
input: 'test/_tmp/input/main.js',
watch: { buildDelay: 1000 },
output: {
file: 'test/_tmp/output/bundle.js',
format: 'cjs'
}
},
{
input: 'test/_tmp/input/main.js',
watch: { buildDelay: 50 },
output: {
file: 'test/_tmp/output/bundle.js',
format: 'cjs'
watcher = rollup.watch(
[
{
input: 'test/_tmp/input/main.js',
output: {
file: 'test/_tmp/output/bundle.js',
format: 'cjs'
}
},
{
input: 'test/_tmp/input/main.js',
watch: { clearScreen: true },
output: {
file: 'test/_tmp/output/bundle.js',
format: 'cjs'
}
},
{
input: 'test/_tmp/input/main.js',
watch: { buildDelay: 1000 },
output: {
file: 'test/_tmp/output/bundle.js',
format: 'cjs'
}
},
{
input: 'test/_tmp/input/main.js',
watch: { buildDelay: 50 },
output: {
file: 'test/_tmp/output/bundle.js',
format: 'cjs'
}
}
}
]);
],
0
);

let startTime;
return sequence(watcher, [
Expand Down

0 comments on commit 6d6a180

Please sign in to comment.