Skip to content

Commit ce7f335

Browse files
committed
Merge pull request nwjs#376 from owenc4a4/test
Test case for nwjs#371, a module for add app to test case
2 parents 95c7d6c + 3bb6032 commit ce7f335

File tree

14 files changed

+255
-112
lines changed

14 files changed

+255
-112
lines changed

tests/app_test.js

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<html>
2+
<head>
3+
</head>
4+
<body>
5+
<p>If there are problem with `require()`: <span style="color:blue" id='msg'></span></p>
6+
<script>
7+
var gui = require('nw.gui');
8+
//gui.Window.get().show();
9+
10+
var result = { ok: true };
11+
12+
try {
13+
require('test');
14+
}
15+
catch (e) {
16+
result.ok = false;
17+
result.error = e;
18+
}
19+
20+
var client = require('../../nw_test_app').createClient({
21+
argv: gui.App.argv,
22+
data: result,
23+
});
24+
25+
if (!client.auto) {
26+
gui.Window.get().show();
27+
} else {
28+
//gui.App.quit();
29+
}
30+
31+
32+
if (result.ok) {
33+
document.getElementById('msg').innerHTML = 'NO';
34+
} else {
35+
document.getElementById('msg').innerHTML = 'YES ' + result.e;
36+
}
37+
</script>
38+
39+
40+
</body>
41+
</html>

tests/app_tests/call_require_with_node-main_set/index.js

Whitespace-only changes.

tests/app_tests/call_require_with_node-main_set/node_modules/test/index.js

Whitespace-only changes.

tests/app_tests/call_require_with_node-main_set/node_modules/test/package.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "node-main",
3+
"main": "index.html",
4+
"node-main": "index.js",
5+
"window": {
6+
"show": false
7+
}
8+
}

tests/app_tests/calls_across_window/mocha_test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var spawn = require('child_process').spawn;
33
var path = require('path');
44
var net = require('net');
55
var server = global.server
6+
var cb;
67

78
describe('AppTest', function(){
89
describe('call across window', function(){
@@ -18,7 +19,7 @@ describe('AppTest', function(){
1819

1920
if (global.auto) exec_argv.push('--auto');
2021

21-
server.on('connection', function(s){
22+
server.on('connection', cb = function(s){
2223
socket = s;
2324
s.setEncoding('utf8');
2425
s.on('end', function(){
@@ -40,6 +41,7 @@ describe('AppTest', function(){
4041
*/
4142
app.kill();
4243
done();
44+
server.removeListener('connection', cb);
4345
})
4446

4547
afterEach(function(){
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
var path = require('path');
2+
var app_test = require('./nw_test_app');
3+
4+
describe('node-main', function() {
5+
describe('create http server in node-main', function() {
6+
it('nw should not close by itself after show devtool',
7+
function(done) {
8+
this.timeout(0);
9+
10+
setTimeout(function(){ done('nw close by itself')}, 3000);
11+
12+
var child = app_test.createChildProcess({
13+
execPath: process.execPath,
14+
appPath: path.join('app_tests', 'show_devtool_after_http_server_created_in_node_main'),
15+
end: function(data, app) {
16+
17+
if (data.success) {
18+
done();
19+
} else {
20+
done('erro');
21+
}
22+
app.kill();
23+
}
24+
});
25+
26+
//child.app.stderr.on('data', function(d){ console.log ('app' + d);});
27+
28+
})
29+
})
30+
31+
describe('call require() in app', function() {
32+
it('nw should can require modules', function(done){
33+
this.timeout(0);
34+
35+
var child = app_test.createChildProcess({
36+
execPath: process.execPath,
37+
appPath: path.join('app_tests', 'call_require_with_node-main_set'),
38+
end: function(data, app) {
39+
40+
if (data.ok) {
41+
done();
42+
} else {
43+
done(data.error);
44+
}
45+
app.kill();
46+
}
47+
});
48+
})
49+
})
50+
51+
})

tests/app_tests/node-remote/mocha_test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var spawn = require('child_process').spawn;
22
var path = require('path');
33
var net = require('net');
44
var server = global.server;
5+
var cb;
56

67
describe('node-remote', function() {
78
describe('enable remote site http://127.0.0.1:80/', function() {
@@ -16,10 +17,10 @@ describe('node-remote', function() {
1617

1718
if (global.auto) exec_argv.push('--auto');
1819

19-
server.on('connection', function(s){
20+
server.on('connection', cb = function(s){
2021
socket = s;
2122
s.setEncoding('utf8');
22-
done();
23+
done();
2324
});
2425
app = spawn(process.execPath, exec_argv);
2526

@@ -30,7 +31,8 @@ describe('node-remote', function() {
3031
after(function(done) {
3132
this.timeout(0);
3233
app.kill();
33-
done();
34+
done();
35+
server.removeListener('connection', cb);
3436
})
3537

3638

tests/app_tests/reload_application/mocha_test.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var spawn = require('child_process').spawn;
33
var path = require('path');
44
var net = require('net');
55
var server = global.server;
6+
var cb;
67

78
describe('AppTest', function(){
89

@@ -20,14 +21,14 @@ describe('AppTest', function(){
2021
});
2122

2223
afterEach(function(){
23-
server.removeAllListeners('connection');
24+
server.removeListener('connection', cb);
2425
});
2526

2627
it('close window after reload', function(done){
2728
this.timeout(0);
2829
exec_argv.push('--type');
2930
exec_argv.push(0);
30-
server.on('connection', function(socket){
31+
server.on('connection', cb = function(socket){
3132
socket.on('end', function(){
3233
//console.log('client disconnect');
3334
});
@@ -63,7 +64,7 @@ describe('AppTest', function(){
6364
this.timeout(0);
6465
exec_argv.push('--type');
6566
exec_argv.push(1);
66-
server.on('connection', function(socket){
67+
server.on('connection', cb = function(socket){
6768
socket.on('end', function(){
6869
});
6970

@@ -95,7 +96,7 @@ describe('AppTest', function(){
9596
exec_argv.push('--type');
9697
exec_argv.push(2);
9798
var times = 0;
98-
server.on('connection', function(socket){
99+
server.on('connection', cb = function(socket){
99100
socket.on('end', function(){
100101
//console.log('client diss');
101102
});
@@ -138,7 +139,7 @@ describe('AppTest', function(){
138139
exec_argv.push('--type');
139140
exec_argv.push(3);
140141
var times = 0;
141-
server.on('connection', function(socket){
142+
server.on('connection', cb = function(socket){
142143
socket.on('end', function(){
143144
//console.log('client diss');
144145
});

tests/app_tests/show_devtool_after_http_server_created_in_node_main/index.html

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,45 @@
44
<body>
55
<script>
66
var gui = require('nw.gui');
7-
8-
/*
9-
* your work
10-
* tell parent process the result of your work, such as 'ok'
11-
*/
12-
function callback(socket) {
13-
14-
gui.Window.get().showDevTools();
15-
16-
setTimeout(function(){
17-
socket.write('ok');
18-
}, 1000);
7+
//gui.Window.get().show();
8+
9+
10+
function showDevTool() {
11+
gui.Window.get().showDevTools();
12+
}
13+
var result = {
14+
success: false
15+
};
1916

17+
var client = require('../../nw_test_app').createClient({
18+
argv: gui.App.argv,
19+
data: result,
20+
delay: 1100 //after 1100ms we send result to server
21+
});
22+
23+
if (client.auto) {
24+
showDevTool();
2025
}
21-
require('../../app_test.js').createClient(gui, callback);
26+
//if nw desn't close by itself,
27+
//the value of result will be 'ok'
28+
setTimeout(function(){
29+
result.success = true;
30+
}, 800);
31+
32+
33+
//we set show=false
34+
//so we hope it can be show when we run it by hard.
35+
if (!client.auto) {
36+
gui.Window.get().show();
37+
}
38+
2239

2340

2441

2542
</script>
2643
<p>nw rocks !</p>
2744
<p>after launch devtool, nw should not close by itself.</p>
28-
<button onclick="gui.Window.get().showDevTools()">open devtool</button>
29-
<button onclick="client.write('click')">click</button>
45+
<button onclick="showDevTool()">open devtool</button>
46+
3047
</body>
3148
</html>

tests/app_tests/show_devtool_after_http_server_created_in_node_main/mocha_test.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)