File tree Expand file tree Collapse file tree 4 files changed +86
-0
lines changed
tests/automatic_tests/nw_fork Expand file tree Collapse file tree 4 files changed +86
-0
lines changed 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
+ var child = fork ( "./fork_module.js" , [ ] , { "execPath" :node_name } ) ;
17
+ var message = "hello world" ;
18
+ var result = false ;
19
+ var gui = require ( 'nw.gui' ) ;
20
+ var port = gui . App . argv [ 0 ] || 13013 ;
21
+
22
+ child . on ( "message" , function ( m ) {
23
+ console . log ( m ) ;
24
+ if ( m == message ) {
25
+ result = true ;
26
+ }
27
+
28
+ var net = require ( 'net' ) ;
29
+ var client = net . createConnection ( { host :"localhost" , port :port } , function ( ) {
30
+ client . write ( result . toString ( ) ) ;
31
+ client . end ( ) ;
32
+ setTimeout ( function ( ) {
33
+ gui . App . quit ( ) ;
34
+ } , 200 ) ;
35
+ } ) ;
36
+ } ) ;
37
+ child . send ( message ) ;
38
+ setTimeout ( function ( ) {
39
+ gui . App . quit ( ) ;
40
+ } , 2000 ) ;
41
+ </ script >
42
+ </ body >
43
+ </ html >
Original file line number Diff line number Diff line change
1
+ var assert = require ( 'assert' ) ;
2
+ var spawn = require ( 'child_process' ) . spawn ;
3
+ var path = require ( 'path' ) ;
4
+ var result = false ;
5
+ describe ( 'fork()' , function ( ) {
6
+ var server = global . server ;
7
+ var get_result = function ( socket ) {
8
+ socket . on ( 'data' , function ( data ) {
9
+ if ( data . toString ( ) == "true" ) {
10
+ result = true ;
11
+ }
12
+ } ) ;
13
+ } ;
14
+
15
+ before ( function ( done ) {
16
+ this . timeout ( 0 ) ;
17
+ server . on ( 'connection' , get_result ) ;
18
+ var app_path = path . join ( 'automatic_tests' , 'nw_fork' ) ;
19
+ var port = global . port || 13013 ;
20
+ var child = spawn ( process . execPath , [ app_path , port ] ) ;
21
+ child . on ( 'exit' , function ( ) {
22
+ done ( ) ;
23
+ } ) ;
24
+ } ) ;
25
+
26
+ it ( "child_process.fork() should have a workaround solution" , function ( done ) {
27
+ assert . equal ( result , true ) ;
28
+ done ( ) ;
29
+ } ) ;
30
+
31
+ after ( function ( done ) {
32
+ server . removeListener ( 'connection' , get_result ) ;
33
+ done ( ) ;
34
+ } ) ;
35
+ } ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" :" test" ,
3
+ "main" :" index.html" ,
4
+ "dependencies" :{}
5
+ }
You can’t perform that action at this time.
0 commit comments