@@ -2137,85 +2137,67 @@ describe('InputPrompt', () => {
21372137 name : 'mid-word' ,
21382138 text : 'hello world' ,
21392139 visualCursor : [ 0 , 3 ] ,
2140- expected : `hel${ chalk . inverse ( 'l' ) } o world` ,
21412140 } ,
21422141 {
21432142 name : 'at the beginning of the line' ,
21442143 text : 'hello' ,
21452144 visualCursor : [ 0 , 0 ] ,
2146- expected : `${ chalk . inverse ( 'h' ) } ello` ,
21472145 } ,
21482146 {
21492147 name : 'at the end of the line' ,
21502148 text : 'hello' ,
21512149 visualCursor : [ 0 , 5 ] ,
2152- expected : `hello${ chalk . inverse ( ' ' ) } ` ,
21532150 } ,
21542151 {
21552152 name : 'on a highlighted token' ,
21562153 text : 'run @path/to/file' ,
21572154 visualCursor : [ 0 , 9 ] ,
2158- expected : `@path/${ chalk . inverse ( 't' ) } o/file` ,
21592155 } ,
21602156 {
21612157 name : 'for multi-byte unicode characters' ,
21622158 text : 'hello 👍 world' ,
21632159 visualCursor : [ 0 , 6 ] ,
2164- expected : `hello ${ chalk . inverse ( '👍' ) } world` ,
21652160 } ,
21662161 {
21672162 name : 'after multi-byte unicode characters' ,
21682163 text : '👍A' ,
21692164 visualCursor : [ 0 , 1 ] ,
2170- expected : `👍${ chalk . inverse ( 'A' ) } ` ,
21712165 } ,
21722166 {
21732167 name : 'at the end of a line with unicode characters' ,
21742168 text : 'hello 👍' ,
21752169 visualCursor : [ 0 , 8 ] ,
2176- expected : `hello 👍` , // skip checking inverse ansi due to ink truncation bug
21772170 } ,
21782171 {
21792172 name : 'at the end of a short line with unicode characters' ,
21802173 text : '👍' ,
21812174 visualCursor : [ 0 , 1 ] ,
2182- expected : `👍${ chalk . inverse ( ' ' ) } ` ,
21832175 } ,
21842176 {
21852177 name : 'on an empty line' ,
21862178 text : '' ,
21872179 visualCursor : [ 0 , 0 ] ,
2188- expected : chalk . inverse ( ' ' ) ,
21892180 } ,
21902181 {
21912182 name : 'on a space between words' ,
21922183 text : 'hello world' ,
21932184 visualCursor : [ 0 , 5 ] ,
2194- expected : `hello${ chalk . inverse ( ' ' ) } world` ,
21952185 } ,
21962186 ] ) (
21972187 'should display cursor correctly $name' ,
2198- async ( { name , text, visualCursor, expected } ) => {
2188+ async ( { text, visualCursor } ) => {
21992189 mockBuffer . text = text ;
22002190 mockBuffer . lines = [ text ] ;
22012191 mockBuffer . viewportVisualLines = [ text ] ;
22022192 mockBuffer . visualCursor = visualCursor as [ number , number ] ;
22032193 props . config . getUseBackgroundColor = ( ) => false ;
22042194
2205- const { stdout , unmount } = await renderWithProviders (
2195+ const renderResult = await renderWithProviders (
22062196 < InputPrompt { ...props } /> ,
22072197 ) ;
2208- await waitFor ( ( ) => {
2209- const frame = stdout . lastFrameRaw ( ) ;
2210- expect ( stripAnsi ( frame ) ) . toContain ( stripAnsi ( expected ) ) ;
2211- if (
2212- name !== 'at the end of a line with unicode characters' &&
2213- name !== 'on a highlighted token'
2214- ) {
2215- expect ( frame ) . toContain ( '\u001b[7m' ) ;
2216- }
2217- } ) ;
2218- unmount ( ) ;
2198+ await renderResult . waitUntilReady ( ) ;
2199+ await expect ( renderResult ) . toMatchSvgSnapshot ( ) ;
2200+ renderResult . unmount ( ) ;
22192201 } ,
22202202 ) ;
22212203 } ) ;
@@ -2231,7 +2213,6 @@ describe('InputPrompt', () => {
22312213 [ 1 , 0 ] ,
22322214 [ 2 , 0 ] ,
22332215 ] ,
2234- expected : `sec${ chalk . inverse ( 'o' ) } nd line` ,
22352216 } ,
22362217 {
22372218 name : 'at the beginning of a line' ,
@@ -2241,7 +2222,6 @@ describe('InputPrompt', () => {
22412222 [ 0 , 0 ] ,
22422223 [ 1 , 0 ] ,
22432224 ] ,
2244- expected : `${ chalk . inverse ( 's' ) } econd line` ,
22452225 } ,
22462226 {
22472227 name : 'at the end of a line' ,
@@ -2251,11 +2231,10 @@ describe('InputPrompt', () => {
22512231 [ 0 , 0 ] ,
22522232 [ 1 , 0 ] ,
22532233 ] ,
2254- expected : `first line${ chalk . inverse ( ' ' ) } ` ,
22552234 } ,
22562235 ] ) (
22572236 'should display cursor correctly $name in a multiline block' ,
2258- async ( { name , text, visualCursor, expected , visualToLogicalMap } ) => {
2237+ async ( { text, visualCursor, visualToLogicalMap } ) => {
22592238 mockBuffer . text = text ;
22602239 mockBuffer . lines = text . split ( '\n' ) ;
22612240 mockBuffer . viewportVisualLines = text . split ( '\n' ) ;
@@ -2265,20 +2244,12 @@ describe('InputPrompt', () => {
22652244 > ;
22662245 props . config . getUseBackgroundColor = ( ) => false ;
22672246
2268- const { stdout , unmount } = await renderWithProviders (
2247+ const renderResult = await renderWithProviders (
22692248 < InputPrompt { ...props } /> ,
22702249 ) ;
2271- await waitFor ( ( ) => {
2272- const frame = stdout . lastFrameRaw ( ) ;
2273- expect ( stripAnsi ( frame ) ) . toContain ( stripAnsi ( expected ) ) ;
2274- if (
2275- name !== 'at the end of a line with unicode characters' &&
2276- name !== 'on a highlighted token'
2277- ) {
2278- expect ( frame ) . toContain ( '\u001b[7m' ) ;
2279- }
2280- } ) ;
2281- unmount ( ) ;
2250+ await renderResult . waitUntilReady ( ) ;
2251+ await expect ( renderResult ) . toMatchSvgSnapshot ( ) ;
2252+ renderResult . unmount ( ) ;
22822253 } ,
22832254 ) ;
22842255
@@ -2295,18 +2266,12 @@ describe('InputPrompt', () => {
22952266 ] ;
22962267 props . config . getUseBackgroundColor = ( ) => false ;
22972268
2298- const { stdout , unmount } = await renderWithProviders (
2269+ const renderResult = await renderWithProviders (
22992270 < InputPrompt { ...props } /> ,
23002271 ) ;
2301- await waitFor ( ( ) => {
2302- const frame = stdout . lastFrameRaw ( ) ;
2303- const lines = frame . split ( '\n' ) ;
2304- // The line with the cursor should just be an inverted space inside the box border
2305- expect (
2306- lines . find ( ( l ) => l . includes ( chalk . inverse ( ' ' ) ) ) ,
2307- ) . not . toBeUndefined ( ) ;
2308- } ) ;
2309- unmount ( ) ;
2272+ await renderResult . waitUntilReady ( ) ;
2273+ await expect ( renderResult ) . toMatchSvgSnapshot ( ) ;
2274+ renderResult . unmount ( ) ;
23102275 } ) ;
23112276 } ) ;
23122277 } ) ;
@@ -2327,22 +2292,14 @@ describe('InputPrompt', () => {
23272292 ] ;
23282293 props . config . getUseBackgroundColor = ( ) => false ;
23292294
2330- const { stdout , unmount } = await renderWithProviders (
2295+ const renderResult = await renderWithProviders (
23312296 < InputPrompt { ...props } /> ,
23322297 ) ;
2333- await waitFor ( ( ) => {
2334- const frame = stdout . lastFrameRaw ( ) ;
2335- // Check that all lines, including the empty one, are rendered.
2336- // This implicitly tests that the Box wrapper provides height for the empty line.
2337- expect ( frame ) . toContain ( 'hello' ) ;
2338- expect ( frame ) . toContain ( 'world' ) ;
2339- expect ( frame ) . toContain ( chalk . inverse ( ' ' ) ) ;
23402298
2341- const outputLines = frame . trim ( ) . split ( '\n' ) ;
2342- // The number of lines should be 2 for the border plus 3 for the content.
2343- expect ( outputLines . length ) . toBe ( 5 ) ;
2344- } ) ;
2345- unmount ( ) ;
2299+ await renderResult . waitUntilReady ( ) ;
2300+ await expect ( renderResult ) . toMatchSvgSnapshot ( ) ;
2301+
2302+ renderResult . unmount ( ) ;
23462303 } ) ;
23472304 } ) ;
23482305
@@ -3955,14 +3912,12 @@ describe('InputPrompt', () => {
39553912 it ( 'should not show inverted cursor when shell is focused' , async ( ) => {
39563913 props . isEmbeddedShellFocused = true ;
39573914 props . focus = false ;
3958- const { stdout , unmount } = await renderWithProviders (
3915+ const renderResult = await renderWithProviders (
39593916 < InputPrompt { ...props } /> ,
39603917 ) ;
3961- await waitFor ( ( ) => {
3962- expect ( stdout . lastFrame ( ) ) . not . toContain ( `{chalk.inverse(' ')}` ) ;
3963- } ) ;
3964- expect ( stdout . lastFrame ( ) ) . toMatchSnapshot ( ) ;
3965- unmount ( ) ;
3918+ await renderResult . waitUntilReady ( ) ;
3919+ await expect ( renderResult ) . toMatchSvgSnapshot ( ) ;
3920+ renderResult . unmount ( ) ;
39663921 } ) ;
39673922 } ) ;
39683923
0 commit comments