Skip to content

Commit

Permalink
Collapse Watch Usage prompt after first run (jestjs#3078)
Browse files Browse the repository at this point in the history
  • Loading branch information
thymikee authored and cpojer committed Mar 6, 2017
1 parent f50a287 commit 4350965
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/jest-cli/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const KEYS = {
QUESTION_MARK: '3f',
T: '74',
U: '75',
W: '77',
};

const ICONS = {
Expand Down
27 changes: 23 additions & 4 deletions packages/jest-cli/src/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

0 comments on commit 4350965

Please sign in to comment.