Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Watch mode flows Runs Jest in a non-interactive environment not showing usage 1`] = `
Array [
"
",
]
`;

exports[`Watch mode flows Runs Jest once by default and shows usage 1`] = `
Array [
"
Expand Down
16 changes: 16 additions & 0 deletions packages/jest-cli/src/__tests__/watch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@ describe('Watch mode flows', () => {
expect(pipe.write.mock.calls.reverse()[0]).toMatchSnapshot();
});

it('Runs Jest in a non-interactive environment not showing usage', () => {
jest.resetModules();
jest.doMock('is-ci', () => true);

const ci_watch = require('../watch').default;
ci_watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);
expect(runJestMock.mock.calls[0][0]).toMatchObject({
contexts,
globalConfig,
onComplete: expect.any(Function),
outputStream: pipe,
testWatcher: new TestWatcher({isWatchMode: true}),
});
expect(pipe.write.mock.calls.reverse()[0]).toMatchSnapshot();
});

it('resolves relative to the package root', () => {
expect(async () => {
await watch(
Expand Down
3 changes: 3 additions & 0 deletions packages/jest-cli/src/check_if_interative.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import isCI from 'is-ci';

export default process.stdout.isTTY && !isCI;
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: I think we could name this file is_interactive so that the import looks like 'import isInteractive from './is_interactive'...

I could even be nice if this was in something like jest-util and then we could use it in other places of the codebase like

packages/jest-cli/src/pre_run_message.js
packages/jest-cli/src/reporters/__tests__/default_reporter.test.js
packages/jest-cli/src/reporters/coverage_reporter.js
packages/jest-cli/src/reporters/default_reporter.js
packages/jest-cli/src/watch.js
packages/jest-util/src/clear_line.js

Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import chalk from 'chalk';
import isInteractive from './check_if_interative';

export default function getNoTestFoundRelatedToChangedFiles(globalConfig) {
return (
chalk.bold('No tests found related to files changed since last commit.\n') +
chalk.dim(
globalConfig.watch
let msg = chalk.bold(
'No tests found related to files changed since last commit.',
);

if (isInteractive) {
msg += chalk.dim(
'\n' + globalConfig.watch
? 'Press `a` to run all tests, or run Jest with `--watchAll`.'
: 'Run Jest without `-o` or with `--all` to run all tests.',
)
);
);
}

return msg;
}
28 changes: 17 additions & 11 deletions packages/jest-cli/src/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import chalk from 'chalk';
import getChangedFilesPromise from './get_changed_files_promise';
import {replacePathSepForRegex} from 'jest-regex-util';
import HasteMap from 'jest-haste-map';
import isCI from 'is-ci';
import isValidPath from './lib/is_valid_path';
import isInteractive from './check_if_interative';
import {print as preRunMessagePrint} from './pre_run_message';
import createContext from './lib/create_context';
import runJest from './run_jest';
Expand All @@ -30,7 +30,6 @@ import TestNamePatternPrompt from './test_name_pattern_prompt';
import WatchPluginRegistry from './lib/watch_plugin_registry';
import {KEYS, CLEAR} from './constants';

const isInteractive = process.stdout.isTTY && !isCI;
let hasExitListener = false;

export default function watch(
Expand Down Expand Up @@ -129,16 +128,23 @@ export default function 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 (shouldDisplayWatchUsage) {
outputStream.write(
usage(globalConfig, watchPlugins, hasSnapshotFailure),
);
shouldDisplayWatchUsage = false; // hide Watch Usage after first run
isWatchUsageDisplayed = true;

// Do not show any Watch Usage related stuff when running in a
// non-interactive environment
if (isInteractive) {
if (shouldDisplayWatchUsage) {
outputStream.write(
usage(globalConfig, watchPlugins, hasSnapshotFailure),
);
shouldDisplayWatchUsage = false; // hide Watch Usage after first run
isWatchUsageDisplayed = true;
} else {
outputStream.write(showToggleUsagePrompt());
shouldDisplayWatchUsage = false;
isWatchUsageDisplayed = false;
}
} else {
outputStream.write(showToggleUsagePrompt());
shouldDisplayWatchUsage = false;
isWatchUsageDisplayed = false;
outputStream.write('\n');
}

testNamePatternPrompt.updateCachedTestResults(results.testResults);
Expand Down