File tree Expand file tree Collapse file tree 6 files changed +121
-0
lines changed Expand file tree Collapse file tree 6 files changed +121
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < meta charset ="utf-8 ">
5
+ < title > nw_fork test</ title >
6
+ </ head >
7
+ < body >
8
+ < p > nw fork test</ p >
9
+
10
+ < script src ="../res/mocha_util.js "> </ script >
11
+ < script src ="mocha_test.js "> </ script >
12
+
13
+ </ body >
14
+
15
+ </ html >
16
+
Original file line number Diff line number Diff line change
1
+ process . on ( "message" , function ( m ) {
2
+ process . send ( m ) ;
3
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="utf8 ">
5
+ < title > test</ title >
6
+ </ head >
7
+ < body >
8
+ < h1 > it works!</ h1 >
9
+ < script type ="text/javascript ">
10
+ var child_process = require ( 'child_process' ) ;
11
+ var fork = child_process . fork ;
12
+ var node_name = "node" ;
13
+ if ( process . platform == "win32" ) {
14
+ node_name += ".exe" ;
15
+ }
16
+
17
+ var path = require ( 'path' ) ;
18
+ var fs = require ( 'fs' ) ;
19
+ var modulePath = path . join ( fs . realpathSync ( '.' ) , 'fork_module.js' ) ;
20
+
21
+ var child = fork ( modulePath , [ ] , { "execPath" :node_name } ) ;
22
+ var message = "hello world" ;
23
+ var result = false ;
24
+ var gui = require ( 'nw.gui' ) ;
25
+ var port = gui . App . argv [ 0 ] || 13013 ;
26
+
27
+ child . on ( "message" , function ( m ) {
28
+ console . log ( m ) ;
29
+ if ( m == message ) {
30
+ result = true ;
31
+ }
32
+
33
+ var socket = require ( 'net' ) . connect ( { port : 13013 } ) ;
34
+ socket . setEncoding ( 'utf8' ) ;
35
+ socket . end ( result . toString ( ) ) ;
36
+ setTimeout ( function ( ) {
37
+ gui . App . quit ( ) ;
38
+ } , 200 ) ;
39
+
40
+
41
+ } ) ;
42
+
43
+ child . send ( message ) ;
44
+ setTimeout ( function ( ) {
45
+ gui . App . quit ( ) ;
46
+ } , 2000 ) ;
47
+ </ script >
48
+ </ body >
49
+ </ html >
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" :" test" ,
3
+ "main" :" index.html" ,
4
+ "dependencies" :{}
5
+ }
Original file line number Diff line number Diff line change
1
+ var path = require ( 'path' ) ;
2
+ var assert = require ( 'assert' ) ;
3
+ var fs = require ( 'fs-extra' ) ;
4
+ var curDir = fs . realpathSync ( '.' ) ;
5
+
6
+ var result = false ;
7
+ describe ( 'fork()' , function ( ) {
8
+
9
+ var child , server , result ;
10
+
11
+ before ( function ( done ) {
12
+ this . timeout ( 0 ) ;
13
+ server = createTCPServer ( 13013 ) ;
14
+ child = spawnChildProcess ( path . join ( curDir , 'internal' ) ) ;
15
+
16
+ server . on ( 'connection' , function ( socket ) {
17
+ socket . setEncoding ( 'utf8' ) ;
18
+ socket . on ( 'data' , function ( data ) {
19
+ result = JSON . parse ( data + '' ) ;
20
+ } ) ;
21
+ } ) ;
22
+
23
+ child . on ( 'exit' , function ( ) {
24
+ done ( ) ;
25
+ } ) ;
26
+
27
+
28
+ } ) ;
29
+
30
+ after ( function ( done ) {
31
+ server . close ( ) ;
32
+ child . kill ( ) ;
33
+ done ( ) ;
34
+ } ) ;
35
+
36
+
37
+
38
+ it ( "child_process.fork() should have a workaround solution" , function ( done ) {
39
+ assert . equal ( result , true ) ;
40
+ done ( ) ;
41
+ } ) ;
42
+
43
+ } ) ;
44
+
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" :" nwfork_wrapper" ,
3
+ "main" :" index.html"
4
+ }
You can’t perform that action at this time.
0 commit comments