(key: string)
| 347 | }; |
| 348 | |
| 349 | const onKeypress = (key: string) => { |
| 350 | if (key === KEYS.CONTROL_C || key === KEYS.CONTROL_D) { |
| 351 | if (typeof stdin.setRawMode === 'function') { |
| 352 | stdin.setRawMode(false); |
| 353 | } |
| 354 | outputStream.write('\n'); |
| 355 | exit(0); |
| 356 | return; |
| 357 | } |
| 358 | |
| 359 | if (activePlugin != null && activePlugin.onKey) { |
| 360 | // if a plugin is activate, Jest should let it handle keystrokes, so ignore |
| 361 | // them here |
| 362 | activePlugin.onKey(key); |
| 363 | return; |
| 364 | } |
| 365 | |
| 366 | // Abort test run |
| 367 | const pluginKeys = getSortedUsageRows(watchPlugins, globalConfig).map( |
| 368 | usage => Number(usage.key).toString(16), |
| 369 | ); |
| 370 | if ( |
| 371 | isRunning && |
| 372 | testWatcher && |
| 373 | ['q', KEYS.ENTER, 'a', 'o', 'f', ...pluginKeys].includes(key) |
| 374 | ) { |
| 375 | testWatcher.setState({interrupted: true}); |
| 376 | return; |
| 377 | } |
| 378 | |
| 379 | const matchingWatchPlugin = filterInteractivePlugins( |
| 380 | watchPlugins, |
| 381 | globalConfig, |
| 382 | ).find(plugin => getPluginKey(plugin, globalConfig) === key); |
| 383 | |
| 384 | if (matchingWatchPlugin != null) { |
| 385 | if (isRunning) { |
| 386 | testWatcher.setState({interrupted: true}); |
| 387 | return; |
| 388 | } |
| 389 | // "activate" the plugin, which has jest ignore keystrokes so the plugin |
| 390 | // can handle them |
| 391 | activePlugin = matchingWatchPlugin; |
| 392 | if (activePlugin.run) { |
| 393 | activePlugin.run(globalConfig, updateConfigAndRun).then( |
| 394 | async shouldRerun => { |
| 395 | activePlugin = null; |
| 396 | if (shouldRerun) { |
| 397 | await updateConfigAndRun(); |
| 398 | } |
| 399 | }, |
| 400 | () => { |
| 401 | activePlugin = null; |
| 402 | onCancelPatternPrompt(); |
| 403 | }, |
| 404 | ); |
| 405 | } else { |
| 406 | activePlugin = null; |
nothing calls this directly
no test coverage detected