@@ -11,28 +11,61 @@ if (!common.isMainThread)
11
11
process . chdir ( fixtures . fixturesDir ) ;
12
12
const repl = require ( 'repl' ) ;
13
13
14
- const server = net . createServer ( ( conn ) => {
15
- repl . start ( '' , conn ) . on ( 'exit' , ( ) => {
16
- conn . destroy ( ) ;
17
- server . close ( ) ;
14
+ {
15
+ const server = net . createServer ( ( conn ) => {
16
+ repl . start ( '' , conn ) . on ( 'exit' , ( ) => {
17
+ conn . destroy ( ) ;
18
+ server . close ( ) ;
19
+ } ) ;
18
20
} ) ;
19
- } ) ;
20
-
21
- const host = common . localhostIPv4 ;
22
- const port = 0 ;
23
- const options = { host, port } ;
24
-
25
- let answer = '' ;
26
- server . listen ( options , function ( ) {
27
- options . port = this . address ( ) . port ;
28
- const conn = net . connect ( options ) ;
29
- conn . setEncoding ( 'utf8' ) ;
30
- conn . on ( 'data' , ( data ) => answer += data ) ;
31
- conn . write ( 'require("baz")\nrequire("./baz")\n.exit\n' ) ;
32
- } ) ;
33
-
34
- process . on ( 'exit' , function ( ) {
35
- assert . strictEqual ( / C a n n o t f i n d m o d u l e / . test ( answer ) , false ) ;
36
- assert . strictEqual ( / E r r o r / . test ( answer ) , false ) ;
37
- assert . strictEqual ( answer , '\'eye catcher\'\n\'perhaps I work\'\n' ) ;
38
- } ) ;
21
+
22
+ const host = common . localhostIPv4 ;
23
+ const port = 0 ;
24
+ const options = { host, port } ;
25
+
26
+ let answer = '' ;
27
+ server . listen ( options , function ( ) {
28
+ options . port = this . address ( ) . port ;
29
+ const conn = net . connect ( options ) ;
30
+ conn . setEncoding ( 'utf8' ) ;
31
+ conn . on ( 'data' , ( data ) => answer += data ) ;
32
+ conn . write ( 'require("baz")\nrequire("./baz")\n.exit\n' ) ;
33
+ } ) ;
34
+
35
+ process . on ( 'exit' , function ( ) {
36
+ assert . strictEqual ( / C a n n o t f i n d m o d u l e / . test ( answer ) , false ) ;
37
+ assert . strictEqual ( / E r r o r / . test ( answer ) , false ) ;
38
+ assert . strictEqual ( answer , '\'eye catcher\'\n\'perhaps I work\'\n' ) ;
39
+ } ) ;
40
+ }
41
+
42
+ // Test for https://github.com/nodejs/node/issues/30808
43
+ // In REPL, we shouldn't look up relative modules from 'node_modules'.
44
+ {
45
+ const server = net . createServer ( ( conn ) => {
46
+ repl . start ( '' , conn ) . on ( 'exit' , ( ) => {
47
+ conn . destroy ( ) ;
48
+ server . close ( ) ;
49
+ } ) ;
50
+ } ) ;
51
+
52
+ const host = common . localhostIPv4 ;
53
+ const port = 0 ;
54
+ const options = { host, port } ;
55
+
56
+ let answer = '' ;
57
+ server . listen ( options , function ( ) {
58
+ options . port = this . address ( ) . port ;
59
+ const conn = net . connect ( options ) ;
60
+ conn . setEncoding ( 'utf8' ) ;
61
+ conn . on ( 'data' , ( data ) => answer += data ) ;
62
+ conn . write ( 'require("./bar")\n.exit\n' ) ;
63
+ } ) ;
64
+
65
+ process . on ( 'exit' , function ( ) {
66
+ assert . strictEqual ( / U n c a u g h t E r r o r : C a n n o t f i n d m o d u l e ' \. \/ b a r ' / . test ( answer ) , true ) ;
67
+
68
+ assert . strictEqual ( / c o d e : ' M O D U L E _ N O T _ F O U N D ' / . test ( answer ) , true ) ;
69
+ assert . strictEqual ( / r e q u i r e S t a c k : \[ ' < r e p l > ' \] / . test ( answer ) , true ) ;
70
+ } ) ;
71
+ }
0 commit comments