1
1
// Helper functions to easily write assertions on Ink instance and frames...
2
2
import { render } from 'ink-testing-library'
3
3
import { expect } from 'vitest' ;
4
- import { sendInputAndWaitForChange } from './shopify-cli-testing-helpers' ;
4
+ import { sendInputAndWait , sendInputAndWaitForChange } from './shopify-cli-testing-helpers' ;
5
5
6
6
// Wait a certain amount of time in milliseconds
7
7
export function wait ( time : number ) {
8
- return new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) )
8
+ return new Promise ( ( resolve ) => setTimeout ( resolve , time ) )
9
9
}
10
10
11
11
export function mustShow ( instance : ReturnType < typeof render > , text : string ) {
@@ -27,8 +27,16 @@ export function expectNFrames(instance: ReturnType<typeof render>, n: number) {
27
27
expect ( instance . frames . length ) . to . equal ( n )
28
28
}
29
29
30
- export async function type ( inst : ReturnType < typeof render > , input : string ) {
31
- await wait ( 10 )
32
- await sendInputAndWaitForChange ( inst , input )
30
+ // Simulate typing
31
+ //Send one letter at a time to enable shortcuts (more than 2 letters at the same time as considered text in shortcuts.ts)
32
+ // we expect some change every time
33
+
34
+ export async function type ( inst : ReturnType < typeof render > , input : string , expectChange : boolean = true ) {
35
+ for ( const i of input . split ( "" ) ) {
36
+ if ( expectChange )
37
+ await sendInputAndWaitForChange ( inst , i )
38
+ else // simulate a small typing pause
39
+ await sendInputAndWait ( inst , 10 , i )
40
+ }
33
41
}
34
42
0 commit comments