Skip to content

Commit 1ee6601

Browse files
committed
Fix helper type() to type one keystroke at a time
1 parent d76621f commit 1ee6601

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

tests/utils/helpers.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Helper functions to easily write assertions on Ink instance and frames...
22
import { render } from 'ink-testing-library'
33
import { expect } from 'vitest';
4-
import { sendInputAndWaitForChange } from './shopify-cli-testing-helpers';
4+
import { sendInputAndWait, sendInputAndWaitForChange } from './shopify-cli-testing-helpers';
55

66
// Wait a certain amount of time in milliseconds
77
export function wait(time: number) {
8-
return new Promise((resolve) => setTimeout(resolve, 100))
8+
return new Promise((resolve) => setTimeout(resolve, time))
99
}
1010

1111
export function mustShow(instance: ReturnType<typeof render>, text: string) {
@@ -27,8 +27,16 @@ export function expectNFrames(instance: ReturnType<typeof render>, n: number) {
2727
expect(instance.frames.length).to.equal(n)
2828
}
2929

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+
}
3341
}
3442

0 commit comments

Comments
 (0)