Skip to content

Commit

Permalink
Merge pull request #1853 from gitchs/nw_fork
Browse files Browse the repository at this point in the history
Add test case for issue 1575
  • Loading branch information
rogerwang committed May 10, 2014
2 parents f120168 + 77d7f4b commit 9fb6169
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/automatic_tests/nw_fork/fork_module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
process.on("message",function(m){
process.send(m);
});
43 changes: 43 additions & 0 deletions tests/automatic_tests/nw_fork/index.html
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>
35 changes: 35 additions & 0 deletions tests/automatic_tests/nw_fork/mocha_test.js
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();
});
});
5 changes: 5 additions & 0 deletions tests/automatic_tests/nw_fork/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name":"test",
"main":"index.html",
"dependencies":{}
}

0 comments on commit 9fb6169

Please sign in to comment.