@@ -7,7 +7,6 @@ const common = require('../common');
77const  assert  =  require ( 'assert' ) ; 
88const  repl  =  require ( 'internal/repl' ) ; 
99const  stream  =  require ( 'stream' ) ; 
10- const  fs  =  require ( 'fs' ) ; 
1110
1211class  ActionStream  extends  stream . Stream  { 
1312  run ( data )  { 
@@ -42,23 +41,11 @@ class ActionStream extends stream.Stream {
4241} 
4342ActionStream . prototype . readable  =  true ; 
4443
45- function  cleanupTmpFile ( )  { 
46-   try  { 
47-     // Write over the file, clearing any history 
48-     fs . writeFileSync ( defaultHistoryPath ,  '' ) ; 
49-   }  catch  ( err )  { 
50-     if  ( err . code  ===  'ENOENT' )  return  true ; 
51-     throw  err ; 
52-   } 
53-   return  true ; 
54- } 
55- 
5644const  tmpdir  =  require ( '../common/tmpdir' ) ; 
5745tmpdir . refresh ( ) ; 
58- const  defaultHistoryPath  =  tmpdir . resolve ( '.node_repl_history' ) ; 
5946
6047{ 
61-   cleanupTmpFile ( ) ; 
48+   const   historyPath   =   tmpdir . resolve ( `. ${ Math . floor ( Math . random ( )   *   10000 ) } ` ) ; 
6249  // Make sure the cursor is at the right places. 
6350  // If the cursor is at the end of a long line and the down key is pressed, 
6451  // Move the cursor to the end of the next line, if shorter. 
@@ -97,7 +84,7 @@ const defaultHistoryPath = tmpdir.resolve('.node_repl_history');
9784  } ) ; 
9885
9986  repl . createInternalRepl ( 
100-     {  NODE_REPL_HISTORY : defaultHistoryPath  } , 
87+     {  NODE_REPL_HISTORY : historyPath  } , 
10188    { 
10289      terminal : true , 
10390      input : new  ActionStream ( ) , 
@@ -112,7 +99,7 @@ const defaultHistoryPath = tmpdir.resolve('.node_repl_history');
11299} 
113100
114101{ 
115-   cleanupTmpFile ( ) ; 
102+   const   historyPath   =   tmpdir . resolve ( `. ${ Math . floor ( Math . random ( )   *   10000 ) } ` ) ; 
116103  // If the last command errored and the user is trying to edit it, 
117104  // The errored line should be removed from history 
118105  const  checkResults  =  common . mustSucceed ( ( r )  =>  { 
@@ -130,12 +117,17 @@ const defaultHistoryPath = tmpdir.resolve('.node_repl_history');
130117    r . input . run ( [ {  name : 'enter'  } ] ) ; 
131118
132119    assert . strictEqual ( r . history . length ,  1 ) ; 
133-     assert . strictEqual ( r . history [ 0 ] ,  'let lineWithMistake = `I have some\rproblem with my syntax`' ) ; 
120+     // Check that the line is properly set in the history structure 
121+     assert . strictEqual ( r . history [ 0 ] ,  'problem with my syntax`\rlet lineWithMistake = `I have some' ) ; 
134122    assert . strictEqual ( r . line ,  '' ) ; 
123+ 
124+     r . input . run ( [ {  name : 'up'  } ] ) ; 
125+     // Check that the line is properly displayed 
126+     assert . strictEqual ( r . line ,  'let lineWithMistake = `I have some\nproblem with my syntax`' ) ; 
135127  } ) ; 
136128
137129  repl . createInternalRepl ( 
138-     {  NODE_REPL_HISTORY : defaultHistoryPath  } , 
130+     {  NODE_REPL_HISTORY : historyPath  } , 
139131    { 
140132      terminal : true , 
141133      input : new  ActionStream ( ) , 
@@ -150,7 +142,7 @@ const defaultHistoryPath = tmpdir.resolve('.node_repl_history');
150142} 
151143
152144{ 
153-   cleanupTmpFile ( ) ; 
145+   const   historyPath   =   tmpdir . resolve ( `. ${ Math . floor ( Math . random ( )   *   10000 ) } ` ) ; 
154146  const  outputBuffer  =  [ ] ; 
155147
156148  // Test that the REPL preview is properly shown on multiline commands 
@@ -182,7 +174,7 @@ const defaultHistoryPath = tmpdir.resolve('.node_repl_history');
182174  } ) ; 
183175
184176  repl . createInternalRepl ( 
185-     {  NODE_REPL_HISTORY : defaultHistoryPath  } , 
177+     {  NODE_REPL_HISTORY : historyPath  } , 
186178    { 
187179      preview : true , 
188180      terminal : true , 
0 commit comments