@@ -78,6 +78,7 @@ const tests = [
78
78
} ,
79
79
{
80
80
env : { NODE_REPL_HISTORY : defaultHistoryPath } ,
81
+ checkTotal : true ,
81
82
test : [ UP , UP , UP , UP , UP , DOWN , DOWN , DOWN , DOWN ] ,
82
83
expected : [ prompt ,
83
84
`${ prompt } Array(100).fill(1).map((e, i) => i ** 2)` ,
@@ -102,6 +103,52 @@ const tests = [
102
103
'1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936,' +
103
104
' 2025, 2116, 2209,...' ,
104
105
prompt ] . filter ( ( e ) => typeof e === 'string' ) ,
106
+ clean : false
107
+ } ,
108
+ { // Creates more history entries to navigate through.
109
+ env : { NODE_REPL_HISTORY : defaultHistoryPath } ,
110
+ test : [
111
+ '555 + 909' , ENTER , // Add a duplicate to the history set.
112
+ 'const foo = true' , ENTER ,
113
+ '555n + 111n' , ENTER ,
114
+ '5 + 5' , ENTER ,
115
+ '55 - 13 === 42' , ENTER
116
+ ] ,
117
+ expected : [ ] ,
118
+ clean : false
119
+ } ,
120
+ {
121
+ env : { NODE_REPL_HISTORY : defaultHistoryPath } ,
122
+ checkTotal : true ,
123
+ preview : false ,
124
+ showEscapeCodes : true ,
125
+ test : [
126
+ '55' , UP , UP , UP , UP , UP , UP , ENTER
127
+ ] ,
128
+ expected : [
129
+ '\x1B[1G' , '\x1B[0J' , prompt , '\x1B[3G' ,
130
+ // '55'
131
+ '5' , '5' ,
132
+ // UP
133
+ '\x1B[1G' , '\x1B[0J' ,
134
+ '> 55 - 13 === 42' , '\x1B[17G' ,
135
+ // UP - skipping 5 + 5
136
+ '\x1B[1G' , '\x1B[0J' ,
137
+ '> 555n + 111n' , '\x1B[14G' ,
138
+ // UP - skipping const foo = true
139
+ '\x1B[1G' , '\x1B[0J' ,
140
+ '> 555 + 909' , '\x1B[12G' ,
141
+ // UP - matching the identical history entry again.
142
+ '\x1B[1G' , '\x1B[0J' ,
143
+ '> 555 + 909' ,
144
+ // UP, UP, ENTER. UPs at the end of the history have no effect.
145
+ '\x1B[12G' ,
146
+ '\r\n' ,
147
+ '1464\n' ,
148
+ '\x1B[1G' , '\x1B[0J' ,
149
+ '> ' , '\x1B[3G' ,
150
+ '\r\n'
151
+ ] ,
105
152
clean : true
106
153
} ,
107
154
{
@@ -190,7 +237,7 @@ const tests = [
190
237
'\x1B[1B' , '\x1B[2K' , '\x1B[1A' ,
191
238
// 6. Backspace
192
239
'\x1B[1G' , '\x1B[0J' ,
193
- prompt , '\x1B[3G'
240
+ prompt , '\x1B[3G' , '\r\n'
194
241
] ,
195
242
clean : true
196
243
} ,
@@ -259,6 +306,11 @@ const tests = [
259
306
// 10. Word right. Cleanup
260
307
'\x1B[0K' , '\x1B[3G' , '\x1B[7C' , ' // n' , '\x1B[10G' ,
261
308
'\x1B[0K' ,
309
+ // 11. ENTER
310
+ '\r\n' ,
311
+ 'Uncaught ReferenceError: functio is not defined\n' ,
312
+ '\x1B[1G' , '\x1B[0J' ,
313
+ prompt , '\x1B[3G' , '\r\n'
262
314
] ,
263
315
clean : true
264
316
} ,
@@ -300,6 +352,7 @@ const tests = [
300
352
prompt ,
301
353
's' ,
302
354
' // Always visible' ,
355
+ prompt ,
303
356
] ,
304
357
clean : true
305
358
}
@@ -330,8 +383,8 @@ function runTest() {
330
383
setImmediate ( runTestWrap , true ) ;
331
384
return ;
332
385
}
333
-
334
386
const lastChunks = [ ] ;
387
+ let i = 0 ;
335
388
336
389
REPL . createInternalRepl ( opts . env , {
337
390
input : new ActionStream ( ) ,
@@ -344,19 +397,20 @@ function runTest() {
344
397
return next ( ) ;
345
398
}
346
399
347
- lastChunks . push ( inspect ( output ) ) ;
400
+ lastChunks . push ( output ) ;
348
401
349
- if ( expected . length ) {
402
+ if ( expected . length && ! opts . checkTotal ) {
350
403
try {
351
- assert . strictEqual ( output , expected [ 0 ] ) ;
404
+ assert . strictEqual ( output , expected [ i ] ) ;
352
405
} catch ( e ) {
353
406
console . error ( `Failed test # ${ numtests - tests . length } ` ) ;
354
407
console . error ( 'Last outputs: ' + inspect ( lastChunks , {
355
408
breakLength : 5 , colors : true
356
409
} ) ) ;
357
410
throw e ;
358
411
}
359
- expected . shift ( ) ;
412
+ // TODO(BridgeAR): Auto close on last chunk!
413
+ i ++ ;
360
414
}
361
415
362
416
next ( ) ;
@@ -365,6 +419,7 @@ function runTest() {
365
419
completer : opts . completer ,
366
420
prompt,
367
421
useColors : false ,
422
+ preview : opts . preview ,
368
423
terminal : true
369
424
} , function ( err , repl ) {
370
425
if ( err ) {
@@ -376,9 +431,13 @@ function runTest() {
376
431
if ( opts . clean )
377
432
cleanupTmpFile ( ) ;
378
433
379
- if ( expected . length !== 0 ) {
434
+ if ( opts . checkTotal ) {
435
+ assert . deepStrictEqual ( lastChunks , expected ) ;
436
+ } else if ( expected . length !== i ) {
437
+ console . error ( tests [ numtests - tests . length - 1 ] ) ;
380
438
throw new Error ( `Failed test # ${ numtests - tests . length } ` ) ;
381
439
}
440
+
382
441
setImmediate ( runTestWrap , true ) ;
383
442
} ) ;
384
443
0 commit comments