@@ -8,6 +8,13 @@ const { spawn } = require('child_process');
88 * tokenizedOutput: string,
99 * rawOutput: string
1010 * })} ParsedOutput
11+ *
12+ * @typedef {({
13+ * typeDelay: number,
14+ * logData: boolean,
15+ * cwd: string,
16+ * env: any
17+ * })} Options
1118 */
1219
1320// Big shoutout to https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797 for super cool reference to all ansi codes
@@ -38,6 +45,8 @@ const ANSI_CHARACTER_MAPS = {
3845 BOLD_2_END : `${ ESC } 23m` ,
3946}
4047
48+ const wait = ms => new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
49+
4150const parseOutput = ( output ) => {
4251 const textAfter = ( question ) => {
4352 const questionIndex = output . indexOf ( question ) + question . length ;
@@ -70,6 +79,11 @@ const parseOutput = (output) => {
7079 } ;
7180} ;
7281
82+ /**
83+ *
84+ * @param {string } commandString
85+ * @param {Options } options
86+ */
7387const createCommandInterface = ( commandString , options ) => {
7488 // /** @type {import('child_process').ChildProcessWithoutNullStreams } */
7589 // let command;
@@ -102,11 +116,13 @@ const createCommandInterface = (commandString, options) => {
102116 throw error ;
103117 } ) ;
104118
105- const type = ( text ) => {
119+ const type = async ( text ) => {
106120 if ( isFinishTypingCalled ) {
107121 throw new Error ( '[cli-testing-library]: `type` cannot be called after `getOutput` or `finishTyping`' ) ;
108122 } ;
109123
124+ await wait ( options . typeDelay ? options . typeDelay : 100 ) ;
125+
110126 return new Promise ( ( resolve ) => {
111127 command . stdin . write ( `${ text } ` , ( ) => {
112128 resolve ( ) ;
0 commit comments