Skip to content

Commit

Permalink
Improve debug logging on failed watch tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed May 21, 2023
1 parent a9a8359 commit a396342
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions test/watch/index.js
Expand Up @@ -10,7 +10,7 @@ const { copy } = require('fs-extra');
const rollup = require('../../dist/rollup');
const { atomicWriteFileSync, wait } = require('../utils');

describe('rollup.watch', () => {
describe.only('rollup.watch', () => {
let watcher;

beforeEach(() => {
Expand Down Expand Up @@ -384,7 +384,7 @@ describe('rollup.watch', () => {
assert.strictEqual(lastEvent, 'create');
}
]);
}).timeout(20_000);
});

it('calls closeWatcher plugin hook', async () => {
let calls = 0;
Expand Down Expand Up @@ -1741,22 +1741,25 @@ describe('rollup.watch', () => {
]);
});
});
}).timeout(20_000);
});

function run(file) {
const resolved = require.resolve(file);
delete require.cache[resolved];
return require(resolved);
}

async function sequence(watcher, events, timeout = 300) {
await new Promise((fulfil, reject) => {
function sequence(watcher, events, timeout = 300) {
const handledEvents = [];
const sequencePromise = new Promise((fulfil, reject) => {
function go(event) {
const next = events.shift();
if (!next) {
handledEvents.push('DONE');
watcher.close();
fulfil();
} else if (typeof next === 'string') {
handledEvents.push(next);
const [eventCode, eventMessage] = next.split(':');
watcher.once('event', event => {
if (event.code !== eventCode) {
Expand All @@ -1778,6 +1781,7 @@ async function sequence(watcher, events, timeout = 300) {
} else {
wait(timeout) // gah, this appears to be necessary to fix random errors
.then(() => {
handledEvents.push(`fn: ${JSON.stringify(event)}`);
next(event);
go();
})
Expand All @@ -1790,7 +1794,13 @@ async function sequence(watcher, events, timeout = 300) {

go();
});
return wait(100);

return Promise.race([
sequencePromise.then(() => wait(100)),
wait(20_000).then(() => {
throw new Error(`Test timed out\n${handledEvents.join('\n')}`);
})
]);
}

function getTimeDiffInMs(previous) {
Expand Down

0 comments on commit a396342

Please sign in to comment.