From 43509650481251e14ed3f632859076cbd872b2bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 6 Mar 2017 13:40:56 +0000 Subject: [PATCH] Collapse Watch Usage prompt after first run (#3078) --- packages/jest-cli/src/constants.js | 1 + packages/jest-cli/src/watch.js | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/jest-cli/src/constants.js b/packages/jest-cli/src/constants.js index a82a66e73d66..b7e24bd42c93 100644 --- a/packages/jest-cli/src/constants.js +++ b/packages/jest-cli/src/constants.js @@ -31,6 +31,7 @@ const KEYS = { QUESTION_MARK: '3f', T: '74', U: '75', + W: '77', }; const ICONS = { diff --git a/packages/jest-cli/src/watch.js b/packages/jest-cli/src/watch.js index 667ad62abd32..201b895dcbc4 100644 --- a/packages/jest-cli/src/watch.js +++ b/packages/jest-cli/src/watch.js @@ -55,7 +55,8 @@ const watch = ( let hasSnapshotFailure = false; let isRunning = false; let testWatcher; - let displayHelp = true; + let shouldDisplayWatchUsage = true; + let isWatchUsageDisplayed = false; testPathPatternPrompt.updateSearchSource(hasteContext); @@ -113,9 +114,14 @@ const watch = ( // The old instance that was passed to Jest will still be interrupted // and prevent test runs from the previous run. testWatcher = new TestWatcher({isWatchMode: true}); - if (displayHelp) { + if (shouldDisplayWatchUsage) { pipe.write(usage(argv, hasSnapshotFailure)); - displayHelp = !process.env.JEST_HIDE_USAGE; + shouldDisplayWatchUsage = false; // hide Watch Usage after first run + isWatchUsageDisplayed = true; + } else { + pipe.write(showToggleUsagePrompt()); + shouldDisplayWatchUsage = false; + isWatchUsageDisplayed = false; } testNamePatternPrompt.updateCachedTestResults(results.testResults); @@ -195,8 +201,14 @@ const watch = ( ); break; case KEYS.QUESTION_MARK: - if (process.env.JEST_HIDE_USAGE) { + break; + case KEYS.W: + if (!shouldDisplayWatchUsage && !isWatchUsageDisplayed) { + pipe.write(ansiEscapes.cursorUp()); + pipe.write(ansiEscapes.eraseDown); pipe.write(usage(argv, hasSnapshotFailure)); + isWatchUsageDisplayed = true; + shouldDisplayWatchUsage = false; } break; } @@ -286,4 +298,11 @@ const usage = (argv, snapshotFailure, delimiter = '\n') => { return messages.filter(message => !!message).join(delimiter) + '\n'; }; +const showToggleUsagePrompt = () => + '\n' + + chalk.bold('Watch Usage: ') + + chalk.dim('Press ') + + 'w' + + chalk.dim(' to show more.'); + module.exports = watch;