@@ -32,7 +32,7 @@ class REPLStream extends ArrayStream {
32
32
return true ;
33
33
}
34
34
35
- wait ( lookFor = PROMPT ) {
35
+ wait ( ) {
36
36
if ( this . waitingForResponse ) {
37
37
throw new Error ( 'Currently waiting for response to another command' ) ;
38
38
}
@@ -43,7 +43,7 @@ class REPLStream extends ArrayStream {
43
43
reject ( err ) ;
44
44
} ;
45
45
const onLine = ( ) => {
46
- if ( this . lines [ this . lines . length - 1 ] . includes ( lookFor ) ) {
46
+ if ( this . lines [ this . lines . length - 1 ] . includes ( PROMPT ) ) {
47
47
this . removeListener ( 'error' , onError ) ;
48
48
this . removeListener ( 'line' , onLine ) ;
49
49
resolve ( this . lines ) ;
@@ -64,8 +64,8 @@ const testMe = repl.start({
64
64
breakEvalOnSigint : true
65
65
} ) ;
66
66
67
- function runAndWait ( cmds , lookFor ) {
68
- const promise = putIn . wait ( lookFor ) ;
67
+ function runAndWait ( cmds ) {
68
+ const promise = putIn . wait ( ) ;
69
69
for ( const cmd of cmds ) {
70
70
if ( typeof cmd === 'string' ) {
71
71
putIn . run ( [ cmd ] ) ;
@@ -84,108 +84,67 @@ async function ordinaryTests() {
84
84
'function koo() { return Promise.resolve(4); }'
85
85
] ) ;
86
86
const testCases = [
87
- [ 'await Promise.resolve(0)' ,
88
- // Auto completion preview with colors stripped.
89
- [ 'awaitaititt Proroomiseisesee.resolveolvelvevee(0)\r' , '0' ]
90
- ] ,
91
- [ '{ a: await Promise.resolve(1) }' ,
92
- // Auto completion preview with colors stripped.
93
- [ '{ a: awaitaititt Proroomiseisesee.resolveolvelvevee(1) }\r' ,
94
- '{ a: 1 }' ]
95
- ] ,
96
- [ '_' , '{ a: 1 }\r' , { line : 0 } ] ,
97
- [ 'let { aa, bb } = await Promise.resolve({ aa: 1, bb: 2 }), f = 5;' ,
98
- [
99
- 'letett { aa, bb } = awaitaititt Proroomiseisesee.resolveolvelvevee' +
100
- '({ aa: 1, bb: 2 }), f = 5;\r'
101
- ]
102
- ] ,
103
- [ 'aa' , [ '1\r' , '1' ] ] ,
104
- [ 'bb' , [ '2\r' , '2' ] ] ,
105
- [ 'f' , [ '5\r' , '5' ] ] ,
106
- [ 'let cc = await Promise.resolve(2)' ,
107
- [ 'letett cc = awaitaititt Proroomiseisesee.resolveolvelvevee(2)\r' ]
108
- ] ,
109
- [ 'cc' , [ '2\r' , '2' ] ] ,
110
- [ 'let dd;' , [ 'letett dd;\r' ] ] ,
111
- [ 'dd' , [ 'undefined\r' ] ] ,
112
- [ 'let [ii, { abc: { kk } }] = [0, { abc: { kk: 1 } }];' ,
113
- [ 'letett [ii, { abc: { kook } }] = [0, { abc: { kook: 1 } }];\r' ] ] ,
114
- [ 'ii' , [ '0\r' , '0' ] ] ,
115
- [ 'kk' , [ '1\r' , '1' ] ] ,
116
- [ 'var ll = await Promise.resolve(2);' ,
117
- [ 'var letl = awaitaititt Proroomiseisesee.resolveolvelvevee(2);\r' ]
118
- ] ,
119
- [ 'll' , [ '2\r' , '2' ] ] ,
120
- [ 'foo(await koo())' ,
121
- [ 'f' , '5oo' , '[Function: foo](awaitaititt kooo())\r' , '4' ] ] ,
122
- [ '_' , [ '4\r' , '4' ] ] ,
123
- [ 'const m = foo(await koo());' ,
124
- [ 'connst module = foo(awaitaititt kooo());\r' ] ] ,
125
- [ 'm' , [ '4\r' , '4' ] ] ,
126
- [ 'const n = foo(await\nkoo());' ,
127
- [ 'connst n = foo(awaitaititt\r' , '... kooo());\r' , 'undefined' ] ] ,
128
- [ 'n' , [ '4\r' , '4' ] ] ,
87
+ [ 'await Promise.resolve(0)' , '0' ] ,
88
+ [ '{ a: await Promise.resolve(1) }' , '{ a: 1 }' ] ,
89
+ [ '_' , '{ a: 1 }' ] ,
90
+ [ 'let { aa, bb } = await Promise.resolve({ aa: 1, bb: 2 }), f = 5;' ] ,
91
+ [ 'aa' , '1' ] ,
92
+ [ 'bb' , '2' ] ,
93
+ [ 'f' , '5' ] ,
94
+ [ 'let cc = await Promise.resolve(2)' ] ,
95
+ [ 'cc' , '2' ] ,
96
+ [ 'let dd;' ] ,
97
+ [ 'dd' ] ,
98
+ [ 'let [ii, { abc: { kk } }] = [0, { abc: { kk: 1 } }];' ] ,
99
+ [ 'ii' , '0' ] ,
100
+ [ 'kk' , '1' ] ,
101
+ [ 'var ll = await Promise.resolve(2);' ] ,
102
+ [ 'll' , '2' ] ,
103
+ [ 'foo(await koo())' , '4' ] ,
104
+ [ '_' , '4' ] ,
105
+ [ 'const m = foo(await koo());' ] ,
106
+ [ 'm' , '4' ] ,
107
+ [ 'const n = foo(await\nkoo());' ,
108
+ [ 'const n = foo(await\r' , '... koo());\r' , 'undefined' ] ] ,
109
+ [ 'n' , '4' ] ,
129
110
// eslint-disable-next-line no-template-curly-in-string
130
- [ '`status: ${(await Promise.resolve({ status: 200 })).status}`' ,
131
- [
132
- '`stratus: ${(awaitaititt Proroomiseisesee.resolveolvelvevee' +
133
- '({ stratus: 200 })).stratus}`\r' ,
134
- "'status: 200'"
135
- ]
136
- ] ,
137
- [ 'for (let i = 0; i < 2; ++i) await i' ,
138
- [ 'f' , '5or (lett i = 0; i < 2; ++i) awaitaititt i\r' , 'undefined' ] ] ,
139
- [ 'for (let i = 0; i < 2; ++i) { await i }' ,
140
- [ 'f' , '5or (lett i = 0; i < 2; ++i) { awaitaititt i }\r' , 'undefined' ]
141
- ] ,
142
- [ 'await 0' , [ 'awaitaititt 0\r' , '0' ] ] ,
143
- [ 'await 0; function foo() {}' ,
144
- [ 'awaitaititt 0; functionnctionctiontioniononn foo() {}\r' ]
145
- ] ,
146
- [ 'foo' ,
147
- [ 'f' , '5oo' , '[Function: foo]\r' , '[Function: foo]' ] ] ,
148
- [ 'class Foo {}; await 1;' , [ 'class Foo {}; awaitaititt 1;\r' , '1' ] ] ,
149
- [ 'Foo' , [ 'Fooo' , '[Function: Foo]\r' , '[Function: Foo]' ] ] ,
150
- [ 'if (await true) { function bar() {}; }' ,
151
- [ 'if (awaitaititt truee) { functionnctionctiontioniononn bar() {}; }\r' ]
152
- ] ,
153
- [ 'bar' , [ 'barr' , '[Function: bar]\r' , '[Function: bar]' ] ] ,
154
- [ 'if (await true) { class Bar {}; }' ,
155
- [ 'if (awaitaititt truee) { class Bar {}; }\r' ]
156
- ] ,
157
- [ 'Bar' , 'Uncaught ReferenceError: Bar is not defined' ] ,
158
- [ 'await 0; function* gen(){}' ,
159
- [ 'awaitaititt 0; functionnctionctiontioniononn* globalen(){}\r' ]
160
- ] ,
161
- [ 'for (var i = 0; i < 10; ++i) { await i; }' ,
162
- [ 'f' , '5or (var i = 0; i < 10; ++i) { awaitaititt i; }\r' , 'undefined' ] ] ,
163
- [ 'i' , [ '10\r' , '10' ] ] ,
164
- [ 'for (let j = 0; j < 5; ++j) { await j; }' ,
165
- [ 'f' , '5or (lett j = 0; j < 5; ++j) { awaitaititt j; }\r' , 'undefined' ] ] ,
166
- [ 'j' , 'Uncaught ReferenceError: j is not defined' , { line : 0 } ] ,
167
- [ 'gen' ,
168
- [ 'genn' , '[GeneratorFunction: gen]\r' , '[GeneratorFunction: gen]' ]
169
- ] ,
170
- [ 'return 42; await 5;' , 'Uncaught SyntaxError: Illegal return statement' ,
171
- { line : 3 } ] ,
172
- [ 'let o = await 1, p' , [ 'lett os = awaitaititt 1, p\r' ] ] ,
173
- [ 'p' , [ 'undefined\r' ] ] ,
174
- [ 'let q = 1, s = await 2' , [ 'lett que = 1, s = awaitaititt 2\r' ] ] ,
175
- [ 's' , [ '2\r' , '2' ] ] ,
176
- [ 'for await (let i of [1,2,3]) console.log(i)' ,
177
- [
178
- 'f' ,
179
- '5or awaitaititt (lett i of [1,2,3]) connsolelee.logogg(i)\r' ,
180
- '1' ,
181
- '2' ,
182
- '3' ,
183
- 'undefined'
184
- ]
111
+ [ '`status: ${(await Promise.resolve({ status: 200 })).status}`' ,
112
+ "'status: 200'" ] ,
113
+ [ 'for (let i = 0; i < 2; ++i) await i' ] ,
114
+ [ 'for (let i = 0; i < 2; ++i) { await i }' ] ,
115
+ [ 'await 0' , '0' ] ,
116
+ [ 'await 0; function foo() {}' ] ,
117
+ [ 'foo' , '[Function: foo]' ] ,
118
+ [ 'class Foo {}; await 1;' , '1' ] ,
119
+ [ 'Foo' , '[Function: Foo]' ] ,
120
+ [ 'if (await true) { function bar() {}; }' ] ,
121
+ [ 'bar' , '[Function: bar]' ] ,
122
+ [ 'if (await true) { class Bar {}; }' ] ,
123
+ [ 'Bar' , 'Uncaught ReferenceError: Bar is not defined' ] ,
124
+ [ 'await 0; function* gen(){}' ] ,
125
+ [ 'for (var i = 0; i < 10; ++i) { await i; }' ] ,
126
+ [ 'i' , '10' ] ,
127
+ [ 'for (let j = 0; j < 5; ++j) { await j; }' ] ,
128
+ [ 'j' , 'Uncaught ReferenceError: j is not defined' , { line : 0 } ] ,
129
+ [ 'gen' , '[GeneratorFunction: gen]' ] ,
130
+ [ 'return 42; await 5;' , 'Uncaught SyntaxError: Illegal return statement' ,
131
+ { line : 3 } ] ,
132
+ [ 'let o = await 1, p' ] ,
133
+ [ 'p' ] ,
134
+ [ 'let q = 1, s = await 2' ] ,
135
+ [ 's' , '2' ] ,
136
+ [ 'for await (let i of [1,2,3]) console.log(i)' ,
137
+ [
138
+ 'for await (let i of [1,2,3]) console.log(i)\r' ,
139
+ '1' ,
140
+ '2' ,
141
+ '3' ,
142
+ 'undefined'
143
+ ]
185
144
]
186
145
] ;
187
146
188
- for ( const [ input , expected , options = { } ] of testCases ) {
147
+ for ( const [ input , expected = [ ` ${ input } \r` ] , options = { } ] of testCases ) {
189
148
console . log ( `Testing ${ input } ` ) ;
190
149
const toBeRun = input . split ( '\n' ) ;
191
150
const lines = await runAndWait ( toBeRun ) ;
@@ -216,7 +175,7 @@ async function ctrlCTest() {
216
175
'await timeout(100000)' ,
217
176
{ ctrl : true , name : 'c' }
218
177
] ) , [
219
- 'awaitaititt timeoutmeouteoutoututt (100000)\r' ,
178
+ 'await timeout (100000)\r' ,
220
179
'Uncaught:' ,
221
180
'[Error [ERR_SCRIPT_EXECUTION_INTERRUPTED]: ' +
222
181
'Script execution was interrupted by `SIGINT`] {' ,
0 commit comments