@@ -7,7 +7,6 @@ const common = require('../common');
7
7
const assert = require ( 'assert' ) ;
8
8
const repl = require ( 'internal/repl' ) ;
9
9
const stream = require ( 'stream' ) ;
10
- const fs = require ( 'fs' ) ;
11
10
12
11
class ActionStream extends stream . Stream {
13
12
run ( data ) {
@@ -42,23 +41,11 @@ class ActionStream extends stream.Stream {
42
41
}
43
42
ActionStream . prototype . readable = true ;
44
43
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
-
56
44
const tmpdir = require ( '../common/tmpdir' ) ;
57
45
tmpdir . refresh ( ) ;
58
- const defaultHistoryPath = tmpdir . resolve ( '.node_repl_history' ) ;
59
46
60
47
{
61
- cleanupTmpFile ( ) ;
48
+ const historyPath = tmpdir . resolve ( `. ${ Math . floor ( Math . random ( ) * 10000 ) } ` ) ;
62
49
// Make sure the cursor is at the right places.
63
50
// If the cursor is at the end of a long line and the down key is pressed,
64
51
// Move the cursor to the end of the next line, if shorter.
@@ -97,7 +84,7 @@ const defaultHistoryPath = tmpdir.resolve('.node_repl_history');
97
84
} ) ;
98
85
99
86
repl . createInternalRepl (
100
- { NODE_REPL_HISTORY : defaultHistoryPath } ,
87
+ { NODE_REPL_HISTORY : historyPath } ,
101
88
{
102
89
terminal : true ,
103
90
input : new ActionStream ( ) ,
@@ -112,7 +99,7 @@ const defaultHistoryPath = tmpdir.resolve('.node_repl_history');
112
99
}
113
100
114
101
{
115
- cleanupTmpFile ( ) ;
102
+ const historyPath = tmpdir . resolve ( `. ${ Math . floor ( Math . random ( ) * 10000 ) } ` ) ;
116
103
// If the last command errored and the user is trying to edit it,
117
104
// The errored line should be removed from history
118
105
const checkResults = common . mustSucceed ( ( r ) => {
@@ -130,12 +117,17 @@ const defaultHistoryPath = tmpdir.resolve('.node_repl_history');
130
117
r . input . run ( [ { name : 'enter' } ] ) ;
131
118
132
119
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' ) ;
134
122
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`' ) ;
135
127
} ) ;
136
128
137
129
repl . createInternalRepl (
138
- { NODE_REPL_HISTORY : defaultHistoryPath } ,
130
+ { NODE_REPL_HISTORY : historyPath } ,
139
131
{
140
132
terminal : true ,
141
133
input : new ActionStream ( ) ,
@@ -150,7 +142,7 @@ const defaultHistoryPath = tmpdir.resolve('.node_repl_history');
150
142
}
151
143
152
144
{
153
- cleanupTmpFile ( ) ;
145
+ const historyPath = tmpdir . resolve ( `. ${ Math . floor ( Math . random ( ) * 10000 ) } ` ) ;
154
146
const outputBuffer = [ ] ;
155
147
156
148
// Test that the REPL preview is properly shown on multiline commands
@@ -182,7 +174,7 @@ const defaultHistoryPath = tmpdir.resolve('.node_repl_history');
182
174
} ) ;
183
175
184
176
repl . createInternalRepl (
185
- { NODE_REPL_HISTORY : defaultHistoryPath } ,
177
+ { NODE_REPL_HISTORY : historyPath } ,
186
178
{
187
179
preview : true ,
188
180
terminal : true ,
0 commit comments