Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
396cd18
Start adding tapable
rogeliog Jan 17, 2018
c04edc7
Use test_path_pattern as a plugin
rogeliog Jan 19, 2018
1f74aa1
Use test_name_pattern as a plugin
rogeliog Jan 19, 2018
03b53b1
Use quit as a plugin
rogeliog Jan 19, 2018
1aeafb8
Fix test interruption
rogeliog Jan 19, 2018
b40f604
Use update snapshot as a plugin
rogeliog Jan 19, 2018
6e97a6e
Use update snapshot interactive as a plugin
rogeliog Jan 25, 2018
ef14ade
Change API to use a class instance
rogeliog Jan 26, 2018
8b999ed
Merge branch 'master' into simpler-plugins
rogeliog Jan 26, 2018
2604965
A bit of clean up and make tests pass
rogeliog Jan 26, 2018
ffc85f1
Change plugin implementation to not use tapable
rogeliog Feb 2, 2018
053d9e4
Better sorting implementation
rogeliog Feb 2, 2018
2036be9
Add back third party plugin functionality
rogeliog Feb 2, 2018
40c4265
Fix flow
rogeliog Feb 2, 2018
44c82ba
Merge branch 'master' into simpler-plugins
rogeliog Feb 2, 2018
7767b71
Fix ESLint
rogeliog Feb 2, 2018
2b084f8
Reset file to state of master
rogeliog Feb 2, 2018
58f1717
Update failing snapshot
rogeliog Feb 2, 2018
13f08e5
Merge branch 'master' into simpler-plugins
rogeliog Feb 6, 2018
d4ecb92
Remove hasSnapshotFailure and hasSnapshotFailureInteractive
rogeliog Feb 6, 2018
8f6513e
Async await for showPrompt and clear active plugin on file change
rogeliog Feb 6, 2018
401e44b
Fix snapshot failure
rogeliog Feb 6, 2018
9ac7d94
Reenable tests
rogeliog Feb 6, 2018
25e0c4b
Implement shouldRunTestSuite
rogeliog Feb 6, 2018
4a68617
Add changelog
rogeliog Feb 6, 2018
3dc8c06
Clean up watch.js a bit
rogeliog Feb 6, 2018
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
Prev Previous commit
Next Next commit
Remove hasSnapshotFailure and hasSnapshotFailureInteractive
  • Loading branch information
rogeliog committed Feb 6, 2018
commit d4ecb9207c64a8924aa9d51d5a377cf8318c4952
12 changes: 10 additions & 2 deletions packages/jest-cli/src/plugins/update_snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
*/
import type {GlobalConfig} from 'types/Config';
import WatchPlugin from '../watch_plugin';
import type {JestHookSubscriber} from '../jest_hooks';

class UpdateSnapshotsPlugin extends WatchPlugin {
_hasSnapshotFailure: boolean;
showPrompt(
globalConfig: GlobalConfig,
updateConfigAndRun: Function,
Expand All @@ -18,9 +20,15 @@ class UpdateSnapshotsPlugin extends WatchPlugin {
return Promise.resolve(false);
}

getUsageRow(globalConfig: GlobalConfig, hasSnapshotFailures: boolean) {
registerHooks(hooks: JestHookSubscriber) {
hooks.testRunComplete(results => {
this._hasSnapshotFailure = results.snapshot.failure;
});
}

getUsageRow(globalConfig: GlobalConfig) {
return {
hide: !hasSnapshotFailures,
hide: !this._hasSnapshotFailure,
key: 'u'.codePointAt(0),
prompt: 'update failing snapshots',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class UpdateSnapshotInteractivePlugin extends WatchPlugin {
}
}

getUsageRow(globalConfig: GlobalConfig, hasSnapshotFailures: boolean) {
getUsageRow(globalConfig: GlobalConfig) {
return {
hide:
!this._failedSnapshotTestPaths ||
Expand Down
63 changes: 13 additions & 50 deletions packages/jest-cli/src/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import exit from 'exit';
import {replacePathSepForRegex} from 'jest-regex-util';
import HasteMap from 'jest-haste-map';
import isValidPath from './lib/is_valid_path';
import {getFailedSnapshotTests, isInteractive} from 'jest-util';
import {isInteractive} from 'jest-util';
import {print as preRunMessagePrint} from './pre_run_message';
import createContext from './lib/create_context';
import runJest from './run_jest';
Expand Down Expand Up @@ -48,18 +48,16 @@ const INTERNAL_PLUGINS = [
const getSortedUsageRows = (
watchPlugins: Array<WatchPlugin>,
globalConfig: GlobalConfig,
hasSnapshotFailure: boolean,
) => {
const internalPlugins = watchPlugins
.slice(0, INTERNAL_PLUGINS.length)
.map(p => p.getUsageRow(globalConfig, hasSnapshotFailure))
.filter(usage => usage && !usage.hide);
.map(p => p.getUsageRow(globalConfig))
.filter(usage => !usage.hide);

const thirdPartyPlugins = watchPlugins
.slice(INTERNAL_PLUGINS.length)
.map(p => p.getUsageRow(globalConfig, hasSnapshotFailure))
.filter(usage => usage && !usage.hide)
// $FlowFixMe a and b will not be null or undefined
.map(p => p.getUsageRow(globalConfig))
.filter(usage => !usage.hide)
.sort((a, b) => a.key - b.key);
Copy link
Member

Choose a reason for hiding this comment

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

I like q being at the bottom, no biggie, though 🙂


return internalPlugins.concat(thirdPartyPlugins);
Expand Down Expand Up @@ -136,13 +134,10 @@ export default function watch(

const failedTestsCache = new FailedTestsCache();
const prompt = new Prompt();
let failedSnapshotTestPaths = [];
let searchSources = contexts.map(context => ({
context,
searchSource: new SearchSource(context),
}));
let hasSnapshotFailure = false;
let hasSnapshotFailureInteractive = false;
let isRunning = false;
let testWatcher;
let shouldDisplayWatchUsage = true;
Expand Down Expand Up @@ -202,9 +197,6 @@ export default function watch(
onComplete: results => {
isRunning = false;
hooks.getEmitter().testRunComplete(results);
failedSnapshotTestPaths = getFailedSnapshotTests(results);
hasSnapshotFailure = !!results.snapshot.failure;
hasSnapshotFailureInteractive = failedSnapshotTestPaths.length > 0;

// Create a new testWatcher instance so that re-runs won't be blocked.
// The old instance that was passed to Jest will still be interrupted
Expand All @@ -215,14 +207,7 @@ export default function watch(
// non-interactive environment
if (isInteractive) {
if (shouldDisplayWatchUsage) {
outputStream.write(
usage(
globalConfig,
watchPlugins,
hasSnapshotFailure,
hasSnapshotFailureInteractive,
),
);
outputStream.write(usage(globalConfig, watchPlugins));
shouldDisplayWatchUsage = false; // hide Watch Usage after first run
isWatchUsageDisplayed = true;
} else {
Expand Down Expand Up @@ -261,12 +246,9 @@ export default function watch(
}

// Abort test run
const pluginKeys = getSortedUsageRows(
watchPlugins,
globalConfig,
hasSnapshotFailure,
// $FlowFixMe usage will be present
).map(usage => Number(usage.key).toString(16));
const pluginKeys = getSortedUsageRows(watchPlugins, globalConfig).map(
usage => Number(usage.key).toString(16),
);
if (
isRunning &&
testWatcher &&
Expand All @@ -279,8 +261,7 @@ export default function watch(
}

const matchingWatchPlugin = watchPlugins.find(plugin => {
const usageRow =
plugin.getUsageRow(globalConfig, hasSnapshotFailure) || {};
const usageRow = plugin.getUsageRow(globalConfig) || {};

return usageRow.key === parseInt(key, 16);
});
Expand Down Expand Up @@ -341,14 +322,7 @@ export default function watch(
if (!shouldDisplayWatchUsage && !isWatchUsageDisplayed) {
outputStream.write(ansiEscapes.cursorUp());
outputStream.write(ansiEscapes.eraseDown);
outputStream.write(
usage(
globalConfig,
watchPlugins,
hasSnapshotFailure,
hasSnapshotFailureInteractive,
),
);
outputStream.write(usage(globalConfig, watchPlugins));
isWatchUsageDisplayed = true;
shouldDisplayWatchUsage = false;
}
Expand All @@ -359,14 +333,7 @@ export default function watch(
const onCancelPatternPrompt = () => {
outputStream.write(ansiEscapes.cursorHide);
outputStream.write(ansiEscapes.clearScreen);
outputStream.write(
usage(
globalConfig,
watchPlugins,
hasSnapshotFailure,
hasSnapshotFailureInteractive,
),
);
outputStream.write(usage(globalConfig, watchPlugins));
outputStream.write(ansiEscapes.cursorShow);
};

Expand Down Expand Up @@ -406,8 +373,6 @@ const activeFilters = (globalConfig: GlobalConfig, delimiter = '\n') => {
const usage = (
globalConfig,
watchPlugins: Array<WatchPlugin>,
snapshotFailure,
snapshotFailureInteractive,
delimiter = '\n',
) => {
const messages = [
Expand Down Expand Up @@ -437,14 +402,12 @@ const usage = (
chalk.dim(' to only run tests related to changed files.')
: null,

...getSortedUsageRows(watchPlugins, globalConfig, snapshotFailure).map(
...getSortedUsageRows(watchPlugins, globalConfig).map(
plugin =>
chalk.dim(' \u203A Press') +
' ' +
// $FlowFixMe plugin will be present
String.fromCodePoint(plugin.key) +
' ' +
// $FlowFixMe plugin will be present
chalk.dim(`to ${plugin.prompt}.`),
),

Expand Down
7 changes: 3 additions & 4 deletions packages/jest-cli/src/watch_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ class WatchPlugin {

registerHooks(hooks: JestHookSubscriber) {}

getUsageRow(
globalConfig: GlobalConfig,
hasFailedSnapshots: boolean,
): ?UsageRow {}
getUsageRow(globalConfig: GlobalConfig): UsageRow {
return {hide: true, key: 0, prompt: ''};
}

onData(value: string) {}

Expand Down