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

Collapse Watch Usage prompt after first run #3078

Merged
merged 1 commit into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
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
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

It appears that the intention behind w is the same as ?. IMO either ? should be removed, or they should be treated identically.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, that's right, I've missed that. I think we should get rid of the question mark.

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;