-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1853 from gitchs/nw_fork
Add test case for issue 1575
- Loading branch information
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
process.on("message",function(m){ | ||
process.send(m); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf8"> | ||
<title>test</title> | ||
</head> | ||
<body> | ||
<h1>it works!</h1> | ||
<script type="text/javascript"> | ||
var child_process = require('child_process'); | ||
var fork = child_process.fork; | ||
var node_name = "node"; | ||
if (process.platform == "win32"){ | ||
node_name += ".exe"; | ||
} | ||
var child = fork("./fork_module.js",[],{"execPath":node_name}); | ||
var message = "hello world"; | ||
var result = false; | ||
var gui = require('nw.gui'); | ||
var port = gui.App.argv[0] || 13013; | ||
|
||
child.on("message",function(m){ | ||
console.log(m); | ||
if (m == message){ | ||
result = true; | ||
} | ||
|
||
var net = require('net'); | ||
var client = net.createConnection({host:"localhost",port:port},function(){ | ||
client.write(result.toString()); | ||
client.end(); | ||
setTimeout(function(){ | ||
gui.App.quit(); | ||
},200); | ||
}); | ||
}); | ||
child.send(message); | ||
setTimeout(function(){ | ||
gui.App.quit(); | ||
},2000); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var assert = require('assert'); | ||
var spawn = require('child_process').spawn; | ||
var path = require('path'); | ||
var result = false; | ||
describe('fork()',function(){ | ||
var server = global.server; | ||
var get_result = function(socket){ | ||
socket.on('data',function(data){ | ||
if (data.toString() == "true"){ | ||
result = true; | ||
} | ||
}); | ||
}; | ||
|
||
before(function(done){ | ||
this.timeout(0); | ||
server.on('connection',get_result); | ||
var app_path = path.join('automatic_tests','nw_fork'); | ||
var port = global.port || 13013; | ||
var child = spawn(process.execPath,[app_path,port]); | ||
child.on('exit',function(){ | ||
done(); | ||
}); | ||
}); | ||
|
||
it("child_process.fork() should have a workaround solution",function(done){ | ||
assert.equal(result,true); | ||
done(); | ||
}); | ||
|
||
after(function(done){ | ||
server.removeListener('connection',get_result); | ||
done(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name":"test", | ||
"main":"index.html", | ||
"dependencies":{} | ||
} |