MCPcopy
hub / github.com/vitest-dev/vitest / _keypressHandler

Function _keypressHandler

packages/vitest/src/node/stdin.ts:82–163  ·  view source on GitHub ↗
(str: string, key: any)

Source from the content-addressed store, hash-verified

80 let latestFilename = ''
81
82 async function _keypressHandler(str: string, key: any) {
83 // Cancel run and exit when ctrl-c or esc is pressed.
84 // If cancelling takes long and key is pressed multiple times, exit forcefully.
85 if (
86 str === '\x03'
87 || str === '\x1B'
88 || (key && key.ctrl && key.name === 'c')
89 ) {
90 if (!ctx.isCancelling) {
91 ctx.logger.log(
92 c.red('Cancelling test run. Press CTRL+c again to exit forcefully.\n'),
93 )
94 process.exitCode = 130
95
96 await ctx.cancelCurrentRun('keyboard-input')
97 }
98 return ctx.exit(true)
99 }
100
101 // window not support suspend
102 if (!isWindows && key && key.ctrl && key.name === 'z') {
103 process.kill(process.ppid, 'SIGTSTP')
104 process.kill(process.pid, 'SIGTSTP')
105 return
106 }
107
108 const name = key?.name
109
110 if (ctx.runningPromise) {
111 if (cancelKeys.includes(name)) {
112 await ctx.cancelCurrentRun('keyboard-input')
113 }
114 return
115 }
116
117 // quit
118 if (name === 'q') {
119 return ctx.exit(true)
120 }
121
122 // help
123 if (name === 'h') {
124 return printShortcutsHelp()
125 }
126 // update snapshot
127 if (name === 'u') {
128 return ctx.updateSnapshot()
129 }
130 // rerun all tests
131 if (name === 'a' || name === 'return') {
132 const files = await ctx._globTestFilepaths()
133 return ctx.changeNamePattern('', files, 'rerun all tests')
134 }
135 // rerun current pattern tests
136 if (name === 'r') {
137 return ctx.rerunFiles()
138 }
139 // rerun only failed tests

Callers 1

keypressHandlerFunction · 0.85

Calls 14

printShortcutsHelpFunction · 0.85
inputProjectNameFunction · 0.85
inputNamePatternFunction · 0.85
inputFilePatternFunction · 0.85
cancelCurrentRunMethod · 0.80
exitMethod · 0.80
updateSnapshotMethod · 0.80
_globTestFilepathsMethod · 0.80
changeNamePatternMethod · 0.80
rerunFilesMethod · 0.80
rerunFailedMethod · 0.80
_initBrowserServersMethod · 0.80

Tested by

no test coverage detected