@@ -4,32 +4,39 @@ const assert = require('assert');
4
4
const repl = require ( 'repl' ) ;
5
5
const vm = require ( 'vm' ) ;
6
6
7
- // Create a dummy stream that does nothing
7
+ // Create a dummy stream that does nothing.
8
8
const stream = new common . ArrayStream ( ) ;
9
9
10
- // Test when useGlobal is false
11
- testContext ( repl . start ( {
12
- input : stream ,
13
- output : stream ,
14
- useGlobal : false
15
- } ) ) ;
10
+ // Test context when useGlobal is false.
11
+ {
12
+ const r = repl . start ( {
13
+ input : stream ,
14
+ output : stream ,
15
+ useGlobal : false
16
+ } ) ;
16
17
17
- function testContext ( repl ) {
18
- const context = repl . createContext ( ) ;
19
- // ensure that the repl context gets its own "console" instance
18
+ // Ensure that the repl context gets its own "console" instance.
19
+ assert ( r . context . console ) ;
20
+
21
+ // Ensure that the repl console instance is not the global one.
22
+ assert . notStrictEqual ( r . context . console , console ) ;
23
+
24
+ const context = r . createContext ( ) ;
25
+ // Ensure that the repl context gets its own "console" instance.
20
26
assert ( context . console instanceof require ( 'console' ) . Console ) ;
21
27
22
- // ensure that the repl's global property is the context
28
+ // Ensure that the repl's global property is the context.
23
29
assert . strictEqual ( context . global , context ) ;
24
30
25
- // ensure that the repl console instance does not have a setter
26
- assert . throws ( ( ) => context . console = 'foo' , TypeError ) ;
27
- repl . close ( ) ;
31
+ // Ensure that the repl console instance is writable.
32
+ context . console = 'foo' ;
33
+ r . close ( ) ;
28
34
}
29
35
30
- testContextSideEffects ( repl . start ( { input : stream , output : stream } ) ) ;
36
+ // Test for context side effects.
37
+ {
38
+ const server = repl . start ( { input : stream , output : stream } ) ;
31
39
32
- function testContextSideEffects ( server ) {
33
40
assert . ok ( ! server . underscoreAssigned ) ;
34
41
assert . strictEqual ( server . lines . length , 0 ) ;
35
42
0 commit comments