@@ -78,6 +78,7 @@ const tests = [
7878} ,
7979{
8080env : { NODE_REPL_HISTORY : defaultHistoryPath } ,
81+ checkTotal : true ,
8182test : [ UP , UP , UP , UP , UP , DOWN , DOWN , DOWN , DOWN ] ,
8283expected : [ prompt ,
8384`${ prompt } Array(100).fill(1).map((e, i) => i ** 2)` ,
@@ -102,6 +103,52 @@ const tests = [
102103'1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936,' +
103104' 2025, 2116, 2209,...' ,
104105prompt ] . 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+ ] ,
105152clean : true
106153} ,
107154{
@@ -190,7 +237,7 @@ const tests = [
190237'\x1B[1B' , '\x1B[2K' , '\x1B[1A' ,
191238// 6. Backspace
192239'\x1B[1G' , '\x1B[0J' ,
193- prompt , '\x1B[3G'
240+ prompt , '\x1B[3G' , '\r\n'
194241] ,
195242clean : true
196243} ,
@@ -259,6 +306,11 @@ const tests = [
259306// 10. Word right. Cleanup
260307'\x1B[0K' , '\x1B[3G' , '\x1B[7C' , ' // n' , '\x1B[10G' ,
261308'\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'
262314] ,
263315clean : true
264316} ,
@@ -300,6 +352,7 @@ const tests = [
300352prompt ,
301353's' ,
302354' // Always visible' ,
355+ prompt ,
303356] ,
304357clean : true
305358}
@@ -330,8 +383,8 @@ function runTest() {
330383setImmediate ( runTestWrap , true ) ;
331384return ;
332385}
333-
334386const lastChunks = [ ] ;
387+ let i = 0 ;
335388
336389REPL . createInternalRepl ( opts . env , {
337390input : new ActionStream ( ) ,
@@ -344,19 +397,20 @@ function runTest() {
344397return next ( ) ;
345398}
346399
347- lastChunks . push ( inspect ( output ) ) ;
400+ lastChunks . push ( output ) ;
348401
349- if ( expected . length ) {
402+ if ( expected . length && ! opts . checkTotal ) {
350403try {
351- assert . strictEqual ( output , expected [ 0 ] ) ;
404+ assert . strictEqual ( output , expected [ i ] ) ;
352405} catch ( e ) {
353406console . error ( `Failed test # ${ numtests - tests . length } ` ) ;
354407console . error ( 'Last outputs: ' + inspect ( lastChunks , {
355408breakLength : 5 , colors : true
356409} ) ) ;
357410throw e ;
358411}
359- expected . shift ( ) ;
412+ // TODO(BridgeAR): Auto close on last chunk!
413+ i ++ ;
360414}
361415
362416next ( ) ;
@@ -365,6 +419,7 @@ function runTest() {
365419completer : opts . completer ,
366420 prompt,
367421useColors : false ,
422+ preview : opts . preview ,
368423terminal : true
369424} , function ( err , repl ) {
370425if ( err ) {
@@ -376,9 +431,13 @@ function runTest() {
376431if ( opts . clean )
377432cleanupTmpFile ( ) ;
378433
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 ] ) ;
380438throw new Error ( `Failed test # ${ numtests - tests . length } ` ) ;
381439}
440+
382441setImmediate ( runTestWrap , true ) ;
383442} ) ;
384443
0 commit comments