Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(watch): cancel waitForCommand when files change #32761

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions packages/playwright/src/runner/watchMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@ export async function runWatchModeLoop(configLocation: ConfigLocation, initialOp
else
printPrompt();

const waitForCommand = readCommand();
const command = await Promise.race([
onDirtyTests,
readCommand(),
waitForCommand.result,
]);

if (command === 'changed')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: onDirtyTests can only resolve to changed.

waitForCommand.cancel();
if (bufferMode && command === 'changed')
continue;

Expand Down Expand Up @@ -282,7 +284,7 @@ async function runTests(watchOptions: WatchModeOptions, testServerConnection: Te
});
}

function readCommand(): ManualPromise<Command> {
function readCommand(): { result: Promise<Command>, cancel: () => void } {
const result = new ManualPromise<Command>();
const rl = readline.createInterface({ input: process.stdin, escapeCodeTimeout: 50 });
readline.emitKeypressEvents(process.stdin, rl);
Expand Down Expand Up @@ -334,13 +336,14 @@ Change settings
};

process.stdin.on('keypress', handler);
void result.finally(() => {
const cancel = () => {
process.stdin.off('keypress', handler);
rl.close();
if (process.stdin.isTTY)
process.stdin.setRawMode(false);
});
return result;
};
void result.finally(cancel);
return { result, cancel };
}

let showBrowserServer: PlaywrightServer | undefined;
Expand Down
Loading