Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
cleanup constants
  • Loading branch information
SimenB committed May 27, 2018
commit 1e432a54362193715ab99207ffdd68353178c8f9
34 changes: 17 additions & 17 deletions packages/jest-cli/src/__tests__/snapshot_interactive_mode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('SnapshotInteractiveMode', () => {

test('press Q or ESC triggers an abort', () => {
instance.abort = jest.fn();
instance.put(KEYS.Q);
instance.put('q');
instance.put(KEYS.ESCAPE);
expect(instance.abort).toHaveBeenCalledTimes(2);
});
Expand All @@ -100,12 +100,12 @@ describe('SnapshotInteractiveMode', () => {
expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot();
pipe.write.mockClear();

instance.put(KEYS.S);
instance.put('s');
expect(mockCallback).toHaveBeenCalledTimes(1);
expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot();
pipe.write.mockClear();

instance.put(KEYS.R);
instance.put('r');
expect(instance.getSkippedNum()).toBe(0);
expect(mockCallback).nthCalledWith(2, assertions[0], false);
expect(mockCallback).toHaveBeenCalledTimes(2);
Expand All @@ -120,12 +120,12 @@ describe('SnapshotInteractiveMode', () => {
expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot();
pipe.write.mockClear();

instance.put(KEYS.S);
instance.put('s');
expect(mockCallback).toHaveBeenCalledTimes(1);
expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot();
pipe.write.mockClear();

instance.put(KEYS.Q);
instance.put('q');
expect(instance.getSkippedNum()).toBe(0);
expect(mockCallback).nthCalledWith(2, null, false);
expect(mockCallback).toHaveBeenCalledTimes(2);
Expand All @@ -150,7 +150,7 @@ describe('SnapshotInteractiveMode', () => {
expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot();
pipe.write.mockClear();

instance.put(KEYS.U);
instance.put('u');
expect(mockCallback).nthCalledWith(2, assertions[0], true);
expect(mockCallback).toHaveBeenCalledTimes(2);
expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot();
Expand All @@ -170,18 +170,18 @@ describe('SnapshotInteractiveMode', () => {
expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot();
pipe.write.mockClear();

instance.put(KEYS.S);
instance.put('s');
expect(mockCallback).nthCalledWith(2, assertions[1], false);
expect(mockCallback).toHaveBeenCalledTimes(2);
expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot();
pipe.write.mockClear();

instance.put(KEYS.S);
instance.put('s');
expect(mockCallback).toHaveBeenCalledTimes(2);
expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot();
pipe.write.mockClear();

instance.put(KEYS.R);
instance.put('r');
expect(instance.getSkippedNum()).toBe(0);
expect(mockCallback).nthCalledWith(3, assertions[0], false);
expect(mockCallback).toHaveBeenCalledTimes(3);
Expand Down Expand Up @@ -217,14 +217,14 @@ describe('SnapshotInteractiveMode', () => {
expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot();
pipe.write.mockClear();

instance.put(KEYS.U);
instance.put('u');
expect(mockCallback).nthCalledWith(2, assertions[0], true);
expect(mockCallback).nthCalledWith(3, assertions[1], false);
expect(mockCallback).toHaveBeenCalledTimes(3);
expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot();
pipe.write.mockClear();

instance.put(KEYS.U);
instance.put('u');
expect(mockCallback).nthCalledWith(4, assertions[1], true);
expect(mockCallback).toHaveBeenCalledTimes(4);
expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot();
Expand Down Expand Up @@ -265,19 +265,19 @@ describe('SnapshotInteractiveMode', () => {
expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot();
pipe.write.mockClear();

instance.put(KEYS.U);
instance.put('u');
expect(mockCallback).nthCalledWith(2, assertions[0], true);
expect(mockCallback).nthCalledWith(3, assertions[1], false);
expect(mockCallback).toHaveBeenCalledTimes(3);
expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot();
pipe.write.mockClear();

instance.put(KEYS.S);
instance.put('s');
expect(mockCallback).toHaveBeenCalledTimes(3);
expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot();
pipe.write.mockClear();

instance.put(KEYS.R);
instance.put('r');
expect(instance.getSkippedNum()).toBe(0);
expect(mockCallback).nthCalledWith(4, assertions[1], false);
expect(mockCallback).toHaveBeenCalledTimes(4);
Expand Down Expand Up @@ -313,19 +313,19 @@ describe('SnapshotInteractiveMode', () => {
expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot();
pipe.write.mockClear();

instance.put(KEYS.S);
instance.put('s');
expect(mockCallback).nthCalledWith(2, assertions[1], false);
expect(mockCallback).toHaveBeenCalledTimes(2);
expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot();
pipe.write.mockClear();

instance.put(KEYS.U);
instance.put('u');
expect(mockCallback).nthCalledWith(3, assertions[1], true);
expect(mockCallback).toHaveBeenCalledTimes(3);
expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot();
pipe.write.mockClear();

instance.put(KEYS.R);
instance.put('r');
expect(instance.getSkippedNum()).toBe(0);
expect(mockCallback).nthCalledWith(4, assertions[0], false);
expect(mockCallback).toHaveBeenCalledTimes(4);
Expand Down
24 changes: 12 additions & 12 deletions packages/jest-cli/src/__tests__/watch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ describe('Watch mode flows', () => {
watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);
runJestMock.mockReset();

stdin.emit(KEYS.O);
stdin.emit('o');

expect(runJestMock).toBeCalled();
expect(runJestMock.mock.calls[0][0].globalConfig).toMatchObject({
Expand All @@ -511,7 +511,7 @@ describe('Watch mode flows', () => {
watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);
runJestMock.mockReset();

stdin.emit(KEYS.A);
stdin.emit('a');

expect(runJestMock).toBeCalled();
expect(runJestMock.mock.calls[0][0].globalConfig).toMatchObject({
Expand All @@ -534,7 +534,7 @@ describe('Watch mode flows', () => {
watch(globalConfig, contexts, pipe, hasteMapInstances, stdin, hooks);
runJestMock.mockReset();

stdin.emit(KEYS.T);
stdin.emit('t');
['t', 'e', 's', 't'].forEach(key => stdin.emit(key));
stdin.emit(KEYS.ENTER);
await nextTick();
Expand All @@ -553,7 +553,7 @@ describe('Watch mode flows', () => {
watch(globalConfig, contexts, pipe, hasteMapInstances, stdin, hooks);
runJestMock.mockReset();

stdin.emit(KEYS.P);
stdin.emit('p');
['f', 'i', 'l', 'e'].forEach(key => stdin.emit(key));
stdin.emit(KEYS.ENTER);
await nextTick();
Expand All @@ -572,12 +572,12 @@ describe('Watch mode flows', () => {
watch(globalConfig, contexts, pipe, hasteMapInstances, stdin, hooks);
runJestMock.mockReset();

stdin.emit(KEYS.P);
stdin.emit('p');
['f', 'i', 'l', 'e'].forEach(key => stdin.emit(key));
stdin.emit(KEYS.ENTER);
await nextTick();

stdin.emit(KEYS.T);
stdin.emit('t');
['t', 'e', 's', 't'].forEach(key => stdin.emit(key));
stdin.emit(KEYS.ENTER);
await nextTick();
Expand All @@ -600,7 +600,7 @@ describe('Watch mode flows', () => {

hooks.getEmitter().onTestRunComplete({snapshot: {failure: true}});

stdin.emit(KEYS.U);
stdin.emit('u');
await nextTick();

expect(runJestMock.mock.calls[0][0].globalConfig).toMatchObject({
Expand All @@ -609,7 +609,7 @@ describe('Watch mode flows', () => {
watchAll: false,
});

stdin.emit(KEYS.A);
stdin.emit('a');

await nextTick();
// updateSnapshot is not sticky after a run.
Expand All @@ -621,11 +621,11 @@ describe('Watch mode flows', () => {

results = {snapshot: {failure: true}};

stdin.emit(KEYS.A);
stdin.emit('a');
await nextTick();

runJestMock.mockReset();
stdin.emit(KEYS.U);
stdin.emit('u');
await nextTick();

expect(runJestMock.mock.calls[0][0].globalConfig).toMatchObject({
Expand All @@ -651,8 +651,8 @@ describe('Watch mode flows', () => {
const ci_watch = require('../watch').default;
ci_watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);

stdin.emit(KEYS.F);
stdin.emit(KEYS.W);
stdin.emit('f');
stdin.emit('w');

const lastWatchDisplay = pipe.write.mock.calls.reverse()[0][0];
expect(lastWatchDisplay).toMatch('Press a to run all tests.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('Watch mode flows', () => {
watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);

// Write a enter pattern mode
stdin.emit(KEYS.P);
stdin.emit('p');
expect(pipe.write).toBeCalledWith(' pattern › ');

const assertPattern = hex => {
Expand Down Expand Up @@ -142,26 +142,26 @@ describe('Watch mode flows', () => {
contexts[0].config = {rootDir: ''};
watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);

stdin.emit(KEYS.P);
stdin.emit('p');
await nextTick();

['p', '.', '*', '1', '0']

.concat(KEYS.ENTER)
.forEach(key => stdin.emit(key));

stdin.emit(KEYS.T);
stdin.emit('t');
await nextTick();

['t', 'e', 's', 't'].concat(KEYS.ENTER).forEach(key => stdin.emit(key));

await nextTick();

stdin.emit(KEYS.C);
stdin.emit('c');
await nextTick();

pipe.write.mockReset();
stdin.emit(KEYS.P);
stdin.emit('p');
await nextTick();

expect(pipe.write.mock.calls.join('\n')).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('Watch mode flows', () => {
watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);

// Write a enter pattern mode
stdin.emit(KEYS.T);
stdin.emit('t');
expect(pipe.write).toBeCalledWith(' pattern › ');

const assertPattern = hex => {
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-cli/src/snapshot_interactive_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default class SnapshotInteractiveMode {

put(key: string) {
switch (key) {
case KEYS.S:
case 's':
if (this._skippedNum === this._testAssertions.length) break;
this._skippedNum += 1;

Expand All @@ -173,14 +173,14 @@ export default class SnapshotInteractiveMode {
}

break;
case KEYS.U:
case 'u':
this._run(true);
break;
case KEYS.Q:
case 'q':
case KEYS.ESCAPE:
this.abort();
break;
case KEYS.R:
case 'r':
this.restart();
break;
case KEYS.ENTER:
Expand Down
14 changes: 7 additions & 7 deletions packages/jest-cli/src/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export default function watch(
if (
isRunning &&
testWatcher &&
[KEYS.Q, KEYS.ENTER, KEYS.A, KEYS.O, KEYS.F]
['q', KEYS.ENTER, 'a', 'o', 'f']
.concat(pluginKeys)
.indexOf(key) !== -1
) {
Expand Down Expand Up @@ -306,38 +306,38 @@ export default function watch(
case KEYS.ENTER:
startRun(globalConfig);
break;
case KEYS.A:
case 'a':
globalConfig = updateGlobalConfig(globalConfig, {
mode: 'watchAll',
testNamePattern: '',
testPathPattern: '',
});
startRun(globalConfig);
break;
case KEYS.C:
case 'c':
updateConfigAndRun({
mode: 'watch',
testNamePattern: '',
testPathPattern: '',
});
break;
case KEYS.F:
case 'f':
globalConfig = updateGlobalConfig(globalConfig, {
onlyFailures: !globalConfig.onlyFailures,
});
startRun(globalConfig);
break;
case KEYS.O:
case 'o':
globalConfig = updateGlobalConfig(globalConfig, {
mode: 'watch',
testNamePattern: '',
testPathPattern: '',
});
startRun(globalConfig);
break;
case KEYS.QUESTION_MARK:
case '?':
break;
case KEYS.W:
case 'w':
if (!shouldDisplayWatchUsage && !isWatchUsageDisplayed) {
outputStream.write(ansiEscapes.cursorUp());
outputStream.write(ansiEscapes.eraseDown);
Expand Down
17 changes: 1 addition & 16 deletions packages/jest-watch/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,13 @@
const isWindows = process.platform === 'win32';

export const KEYS = {
A: 'a',
ARROW_DOWN: '\u001b[B',
ARROW_LEFT: '\u001b[D',
ARROW_RIGHT: '\u001b[C',
ARROW_UP: '\u001b[A',
BACKSPACE: isWindows
? Buffer.from('08', 'hex').toString()
: Buffer.from('7f', 'hex').toString(),
C: 'c',
BACKSPACE: Buffer.from(isWindows ? '08' : '7f', 'hex').toString(),
CONTROL_C: '\u0003',
CONTROL_D: '\u0004',
ENTER: '\r',
ESCAPE: '\u001b',
F: 'f',
I: 'i',
O: 'o',
P: 'p',
Q: 'q',
QUESTION_MARK: '?',
R: 'r',
S: 's',
T: 't',
U: 'u',
W: 'w',
};
Loading