Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! fixup! Add a brand new watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
novemberborn committed Jul 2, 2023
1 parent 1326724 commit a4b4ab4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
45 changes: 24 additions & 21 deletions test/watch-mode/helpers/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const withFixture = fixture => async (t, task) => {

t.timeout(10_000);

const promise = delay(5000, null, {ref: false}).then(() => {
const promise = Promise.all([delay(5000, null, {ref: false}), next?.()]).finally(() => {
if (idlePromise === promise) {
idlePromise = new Promise(() => {});
assertingIdle = false;
Expand All @@ -96,40 +96,43 @@ export const withFixture = fixture => async (t, task) => {
});
idlePromise = promise;

await next?.();
await promise;
};

let state = {};
let pendingState;

const results = run(args, options);
let nextResult = results.next();
while (true) { // eslint-disable-line no-constant-condition
const item = await Promise.race([nextResult, idlePromise, donePromise]); // eslint-disable-line no-await-in-loop
try {
let nextResult = results.next();
while (true) { // eslint-disable-line no-constant-condition
const item = await Promise.race([nextResult, idlePromise, donePromise]); // eslint-disable-line no-await-in-loop

if (item.value) {
failedIdleAssertion ||= assertingIdle;
if (item.value) {
failedIdleAssertion ||= assertingIdle;

state = (await pendingState) ?? state; // eslint-disable-line no-await-in-loop
const result = item.value;
const {[result.runCount]: handler = handlers.else} = handlers;
pendingState = handler?.call({assertIdle, done, ...operations}, result, state);
state = (await pendingState) ?? state; // eslint-disable-line no-await-in-loop
const result = item.value;
const {[result.runCount]: handler = handlers.else} = handlers;
pendingState = handler?.call({assertIdle, done, ...operations}, result, state);

if (!item.done && !isDone) {
nextResult = results.next();
if (!item.done && !isDone) {
nextResult = results.next();
}
}
}

if (item.done || isDone) {
item.value?.process.send('abort-watcher');
results.return();
break;
if (item.done || isDone) {
item.value?.process.send('abort-watcher');
break;
}
}
}
} finally {
results.return();

if (assertingIdle) await idlePromise;
await pendingState;
// Handle outstanding promises in case they reject.
if (assertingIdle) await idlePromise;

Check failure on line 133 in test/watch-mode/helpers/watch.js

View workflow job for this annotation

GitHub Actions / Lint source files

Expected { after 'if' condition.
await pendingState;
}
},
});

Expand Down
2 changes: 1 addition & 1 deletion test/watch-mode/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ test('ignores changes to compiled files with inline compilation', withFixture('t
await fs.symlink(new URL('../../node_modules', import.meta.url), path.join(fixture.dir, 'node_modules'));
await fixture.watch({
async 1(result) {
t.log(result);
t.log(result.stats);
await this.assertIdle(async () => {
t.log(await fs.readdir(path.join(fixture.dir)));
t.log(await fs.readdir(path.join(fixture.dir, 'build')));
Expand Down

0 comments on commit a4b4ab4

Please sign in to comment.