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

Cache interruptedKeys list in watch keypress event #15228

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 13 additions & 8 deletions packages/jest-core/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,18 @@ export default async function watch(
}
};

const pluginKeys = getSortedUsageRows(watchPlugins, globalConfig).map(usage =>
Number(usage.key).toString(16),
);
const interruptedKeys = new Set([
'q',
KEYS.ENTER,
'a',
'o',
'f',
...pluginKeys,
]);

const onKeypress = (key: string) => {
if (key === KEYS.CONTROL_C || key === KEYS.CONTROL_D) {
if (typeof stdin.setRawMode === 'function') {
Expand All @@ -362,14 +374,7 @@ export default async function watch(
}

// Abort test run
const pluginKeys = getSortedUsageRows(watchPlugins, globalConfig).map(
usage => Number(usage.key).toString(16),
);
if (
isRunning &&
testWatcher &&
['q', KEYS.ENTER, 'a', 'o', 'f', ...pluginKeys].includes(key)
) {
if (isRunning && testWatcher && interruptedKeys.has(key)) {
testWatcher.setState({interrupted: true});
return;
}
Expand Down
Loading