-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Interactive Snapshot Update mode #3831
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
Changes from 1 commit
947805e
290aaab
cbced77
916bcf2
81d73e1
736e666
32127da
8068f36
0c7343d
8b1b701
45e4e1f
eec3d43
f8d4c38
c545898
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,10 @@ | ||
| /** | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will need Facebook's copyright header. Can you copy it from other files? |
||
| * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. An additional grant | ||
| * of patent rights can be found in the PATENTS file in the same directory. | ||
| * | ||
| * @flow | ||
| */ | ||
|
|
||
|
|
@@ -7,13 +13,13 @@ import type {AggregatedResult} from 'types/TestResult'; | |
| const chalk = require('chalk'); | ||
| const ansiEscapes = require('ansi-escapes'); | ||
| const {pluralize} = require('./reporters/utils'); | ||
| const {rightPad} = require('./lib/terminalUtils'); | ||
| const {rightPad} = require('./lib/terminal_utils'); | ||
| const {KEYS} = require('./constants'); | ||
|
|
||
| module.exports = class SnapshotInteractiveMode { | ||
| _pipe: stream$Writable | tty$WriteStream; | ||
| _isActive: boolean; | ||
| _updateTestRunnerConfig: (a: string, jestRunnerOptions: Object) => *; | ||
| _updateTestRunnerConfig: (path: string, shouldUpdateSnapshot: boolean) => *; | ||
| _testFilePaths: Array<string>; | ||
| _countPaths: number; | ||
|
|
||
|
|
@@ -30,13 +36,13 @@ module.exports = class SnapshotInteractiveMode { | |
| this._pipe.write(ansiEscapes.scrollDown); | ||
| this._pipe.write(ansiEscapes.scrollDown); | ||
|
||
|
|
||
| this._pipe.write(ansiEscapes.cursorSavePosition); | ||
| this._pipe.write(ansiEscapes.cursorTo(0, 0)); | ||
|
|
||
| const title = rightPad(' -> Interactive Snapshot Update Activated <-'); | ||
| this._pipe.write(chalk.black.bold.bgYellow(title)); | ||
|
|
||
| this._pipe.write(ansiEscapes.cursorRestorePosition); | ||
| // this._pipe.write(ansiEscapes.cursorSavePosition); | ||
| // this._pipe.write(ansiEscapes.cursorTo(0, 0)); | ||
| // | ||
| // const title = rightPad(' -> Interactive Snapshot Update Activated <-'); | ||
| // this._pipe.write(chalk.black.bold.bgYellow(title)); | ||
| // | ||
| // this._pipe.write(ansiEscapes.cursorRestorePosition); | ||
| this._pipe.write(ansiEscapes.cursorUp(6)); | ||
| this._pipe.write(ansiEscapes.eraseDown); | ||
|
|
||
|
|
@@ -51,17 +57,21 @@ module.exports = class SnapshotInteractiveMode { | |
| '\n' + chalk.bold('Interactive Snapshot Progress'), | ||
| ' \u203A ' + stats, | ||
| '\n' + chalk.bold('Watch Usage'), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to |
||
|
|
||
| chalk.dim(' \u203A Press ') + | ||
| 'u' + | ||
| chalk.dim(' to update failing snapshots.'), | ||
| chalk.dim(' to update failing snapshots for this test.'), | ||
|
|
||
| this._testFilePaths.length > 1 | ||
| ? chalk.dim(' \u203A Press ') + | ||
| 's' + | ||
| chalk.dim(' to skip the current snapshot..') | ||
| 's' + | ||
| chalk.dim(' to skip the current snapshot.') | ||
| : '', | ||
|
|
||
| chalk.dim(' \u203A Press ') + | ||
| 'q' + | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to |
||
| chalk.dim(' to quit interactive snapshot mode.'), | ||
| chalk.dim(' to quit Interactive Snapshot Update Mode.'), | ||
|
|
||
| chalk.dim(' \u203A Press ') + | ||
| 'Enter' + | ||
| chalk.dim(' to trigger a test run.'), | ||
|
|
@@ -75,30 +85,26 @@ module.exports = class SnapshotInteractiveMode { | |
| case KEYS.S: | ||
| const testFilePath = this._testFilePaths.shift(); | ||
| this._testFilePaths.push(testFilePath); | ||
| this._run({}); | ||
| this._run(false); | ||
| break; | ||
|
|
||
| case KEYS.U: | ||
| this._run({updateSnapshot: 'all'}); | ||
| this._run(true); | ||
| break; | ||
|
|
||
| case KEYS.Q: | ||
| case KEYS.ESCAPE: | ||
| this.abort(); | ||
| break; | ||
|
|
||
| case KEYS.ENTER: | ||
| this._run({}); | ||
| this._run(false); | ||
| break; | ||
| default: | ||
| console.log('got key event', key); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| abort() { | ||
| this._isActive = false; | ||
| this._updateTestRunnerConfig('', {}); | ||
| this._updateTestRunnerConfig('', false); | ||
| } | ||
|
|
||
| updateWithResults(results: AggregatedResult) { | ||
|
|
@@ -113,17 +119,17 @@ module.exports = class SnapshotInteractiveMode { | |
| this.abort(); | ||
| return; | ||
| } | ||
| this._run({}); | ||
| this._run(false); | ||
| } | ||
|
|
||
| _run(jestRunnerOptions: Object) { | ||
| _run(shouldUpdateSnapshot: boolean) { | ||
| const testFilePath = this._testFilePaths[0]; | ||
| this._updateTestRunnerConfig(testFilePath, jestRunnerOptions); | ||
| this._updateTestRunnerConfig(testFilePath, shouldUpdateSnapshot); | ||
| } | ||
|
|
||
| run( | ||
| failedSnapshotTestPaths: Array<string>, | ||
| onConfigChange: (path: string, jestRunnerOptions: Object) => *, | ||
| onConfigChange: (path: string, shouldUpdateSnapshot: boolean) => *, | ||
| ) { | ||
| if (!failedSnapshotTestPaths.length) { | ||
| return; | ||
|
|
@@ -133,6 +139,6 @@ module.exports = class SnapshotInteractiveMode { | |
| this._countPaths = this._testFilePaths.length; | ||
| this._updateTestRunnerConfig = onConfigChange; | ||
| this._isActive = true; | ||
| this._run({}); | ||
| this._run(false); | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,7 @@ const watch = ( | |
| const prompt = new Prompt(); | ||
| const testPathPatternPrompt = new TestPathPatternPrompt(outputStream, prompt); | ||
| const testNamePatternPrompt = new TestNamePatternPrompt(outputStream, prompt); | ||
| const snapshotInteracticeMode = new SnapshotInteractiveMode(pipe); | ||
| const snapshotInteracticeMode = new SnapshotInteractiveMode(outputStream); | ||
|
||
| let failedSnapshotTestPaths = []; | ||
| let searchSources = contexts.map(context => ({ | ||
| context, | ||
|
|
@@ -197,8 +197,19 @@ const watch = ( | |
| if (hasSnapshotFailure) { | ||
| snapshotInteracticeMode.run( | ||
| failedSnapshotTestPaths, | ||
| (path: string, jestRunnerOptions: Object) => { | ||
| updateRunnerPatternMatching('watch', '', path, jestRunnerOptions); | ||
| (path: string, shouldUpdateSnapshot: boolean) => { | ||
| // updateRunnerPatternMatching('watch', '', path, jestRunnerOptions); | ||
| globalConfig = updateGlobalConfig(globalConfig, { | ||
| mode: 'watch', | ||
| testNamePattern: '', | ||
| testPathPattern: replacePathSepForRegex(path), | ||
| updateSnapshot: shouldUpdateSnapshot ? 'all' : 'none', | ||
| }); | ||
| startRun(globalConfig); | ||
| globalConfig = updateGlobalConfig(globalConfig, { | ||
| // updateSnapshot is not sticky after a run. | ||
| updateSnapshot: 'none', | ||
| }); | ||
| }, | ||
| ); | ||
| } | ||
|
|
@@ -284,11 +295,12 @@ const watch = ( | |
| filePattern: string, | ||
| jestRunnerOptions = {}, | ||
| ) => { | ||
| updateArgv(argv, watchMode, { | ||
| globalConfig = updateGlobalConfig(globalConfig, { | ||
| mode: watchMode, | ||
| testNamePattern: namePattern, | ||
| testPathPattern: replacePathSepForRegex(filePattern), | ||
| }); | ||
| startRun(jestRunnerOptions); | ||
| startRun(globalConfig); | ||
| }; | ||
|
|
||
| if (typeof stdin.setRawMode === 'function') { | ||
|
|
@@ -354,8 +366,8 @@ const usage = (globalConfig, snapshotFailure, delimiter = '\n') => { | |
|
|
||
| snapshotFailure | ||
| ? chalk.dim(' \u203A Press ') + | ||
| 'i' + | ||
| chalk.dim(' to update failing snapshots interactively.') | ||
| 'i' + | ||
| chalk.dim(' to update failing snapshots interactively.') | ||
| : null, | ||
|
|
||
| chalk.dim(' \u203A Press ') + | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a license not with
@flowpragma