Skip to content

Commit 69bcd9e

Browse files
committed
[test]set timeout can not run when test passed
1 parent d695516 commit 69bcd9e

File tree

5 files changed

+96
-88
lines changed

5 files changed

+96
-88
lines changed

tests/app_tests/calls_across_window/mocha_test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ describe('AppTest', function(){
2222
server.on('connection', cb = function(s){
2323
socket = s;
2424
s.setEncoding('utf8');
25-
s.on('end', function(){
26-
console.log('client dissconnect');
27-
});
25+
2826
done();
2927
});
3028
app = spawn(process.execPath, exec_argv);

tests/app_tests/node-main/mocha_test.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ describe('node-main', function() {
66
it('nw should not close by itself after show devtool',
77
function(done) {
88
this.timeout(0);
9-
10-
setTimeout(function(){ done('nw close by itself')}, 3000);
11-
9+
var result = false;
10+
1211
var child = app_test.createChildProcess({
1312
execPath: process.execPath,
1413
appPath: path.join('app_tests', 'show_devtool_after_http_server_created_in_node_main'),
@@ -19,10 +18,16 @@ describe('node-main', function() {
1918
} else {
2019
done('erro');
2120
}
22-
app.kill();
21+
app.kill();
22+
result = true;
2323
}
2424
});
2525

26+
setTimeout(function(){
27+
if (!result) {
28+
done('nw close by itself')
29+
}
30+
}, 3000);
2631
//child.app.stderr.on('data', function(d){ console.log ('app' + d);});
2732

2833
})

tests/app_tests/plugin/mocha_test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@ var app_test = require('./nw_test_app');
44
describe('Plugin', function() {
55
describe('flash', function(){
66
it('should not crash', function(done) {
7+
var result = false;
78

8-
setTimeout(function(){ done('nw crash.')}, 1800);
99
var child = app_test.createChildProcess({
1010
execPath: process.execPath,
1111
appPath: path.join('app_tests', 'plugin', 'flash'),
1212
end: function(data, app) {
1313
done();
14+
result = true;
1415
app.kill();
1516
}
1617
});
18+
19+
setTimeout(function(){
20+
if (!result) {
21+
done('nw crash.');
22+
}
23+
}, 3000);
24+
25+
1726
})
1827
})
1928
})

tests/app_tests/reload_application/mocha_test.js

Lines changed: 54 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,41 @@ describe('AppTest', function(){
99

1010
describe('reload app (long-to-run)', function(){
1111

12-
var exec_argv;
13-
14-
beforeEach(function(){
15-
exec_argv = [path.join('app_tests', 'reload_application'),
16-
'--port',
17-
global.port];
18-
19-
if (global.auto) exec_argv.push('--auto');
20-
21-
});
2212

13+
var exec_argv = [path.join('app_tests', 'reload_application'),
14+
'--port',
15+
global.port,
16+
'--auto'];
17+
18+
2319
afterEach(function(){
24-
server.removeListener('connection', cb);
20+
try {
21+
server.removeListener('connection', cb);
22+
} catch (e) {
23+
}
24+
2525
});
26+
2627

2728
it('close window after reload', function(done){
2829
this.timeout(0);
2930
exec_argv.push('--type');
30-
exec_argv.push(0);
31-
server.on('connection', cb = function(socket){
32-
socket.on('end', function(){
33-
//console.log('client disconnect');
34-
});
35-
36-
console.log('client connect');
37-
socket.setEncoding('utf8');
38-
socket.on('data', function(data){
39-
});
31+
exec_argv.push(0);
32+
var result = false;
33+
34+
var app = spawn(process.execPath, exec_argv);
35+
app.on('exit', function (code){
36+
if (code != 0) return done('error');
37+
result = true;
38+
done();
4039
});
41-
42-
var app = spawn(process.execPath, exec_argv);
43-
app.on('exit', function (code){
44-
if (code != 0) return done('error');
45-
//console.log('end');
46-
done();
47-
});
4840

49-
if (global.auto){
50-
setTimeout(function(){
51-
41+
setTimeout(function(){
42+
if (!result) {
5243
app.kill();
5344
done("Timeout, Can not close window.");
54-
}, 10000);
5545
}
56-
57-
58-
46+
}, 10000);
5947

6048
})
6149

@@ -64,30 +52,22 @@ describe('AppTest', function(){
6452
this.timeout(0);
6553
exec_argv.push('--type');
6654
exec_argv.push(1);
67-
server.on('connection', cb = function(socket){
68-
socket.on('end', function(){
69-
});
70-
71-
console.log('client connect');
72-
socket.setEncoding('utf8');
73-
socket.on('data', function(data){
74-
});
55+
var result = false;
56+
57+
var app = spawn(process.execPath, exec_argv);
58+
app.on('exit', function (code){
59+
if (code != 0) return done('error');
60+
result = true;
61+
done();
7562
});
76-
77-
var app = spawn(process.execPath, exec_argv);
78-
79-
app.on('exit', function (code){
80-
if (code != 0) return done('error');
81-
//console.log('in 2');
82-
done();
83-
});
8463

85-
if (global.auto){
86-
setTimeout(function(){
64+
setTimeout(function(){
65+
if (!result) {
8766
app.kill();
8867
done("Timeout, Can not quit App.");
89-
}, 10000);
9068
}
69+
}, 10000);
70+
9171

9272
})
9373

@@ -96,12 +76,11 @@ describe('AppTest', function(){
9676
exec_argv.push('--type');
9777
exec_argv.push(2);
9878
var times = 0;
79+
var result = false;
80+
9981
server.on('connection', cb = function(socket){
100-
socket.on('end', function(){
101-
//console.log('client diss');
102-
});
103-
104-
//console.log('client connect');
82+
83+
//console.log('client connect in 1');
10584
socket.setEncoding('utf8');
10685
socket.on('data', function(data){
10786
if (data == 'open'){
@@ -122,15 +101,18 @@ describe('AppTest', function(){
122101

123102
app.on('exit', function (code){
124103
if (code != 0) return done('error');
104+
result = true;
125105
done();
126106
});
127107

128-
if (global.auto && 1 == 2){
129-
setTimeout(function(){
108+
109+
setTimeout(function(){
110+
if (!result) {
130111
app.kill();
131112
done("Timeout, Can not close window.");
132-
}, 10000);
133-
}
113+
}
114+
}, 10000);
115+
134116

135117
})
136118

@@ -139,10 +121,9 @@ describe('AppTest', function(){
139121
exec_argv.push('--type');
140122
exec_argv.push(3);
141123
var times = 0;
124+
var result = false;
125+
142126
server.on('connection', cb = function(socket){
143-
socket.on('end', function(){
144-
//console.log('client diss');
145-
});
146127

147128
//console.log('client connect');
148129
socket.setEncoding('utf8');
@@ -165,15 +146,18 @@ describe('AppTest', function(){
165146

166147
app.on('exit', function (code){
167148
if (code != 0) return done('error');
149+
result = true;
168150
done();
169151
});
170152

171-
if (global.auto){
172-
setTimeout(function(){
153+
154+
setTimeout(function(){
155+
if (!result) {
173156
app.kill();
174157
done("Timeout, Can not quit App.");
175-
}, 10000);
176-
}
158+
}
159+
}, 10000);
160+
177161

178162
})
179163

tests/app_tests/start_app/mocha_test.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe('different method of starting app (long-to-run)', function() {
3434

3535
it('start from nw that package.json in the same folder', function(done) {
3636
this.timeout(0);
37+
var result = false;
3738

3839
if (os.platform() == 'darwin') {
3940
//mac don't have this method
@@ -43,33 +44,41 @@ describe('different method of starting app (long-to-run)', function() {
4344

4445
var app = spawn(execPath);
4546
app.on('exit', function() {
47+
result = true;
4648
done();
4749
});
48-
setTimeout(function(){
49-
done('timeout');
50-
app.kill();
50+
51+
setTimeout(function() {
52+
if (!result) {
53+
done('timeout');
54+
app.kill();
55+
}
5156
}, 10000);
5257

5358
})
5459

5560
it('start from app.nw', function(done) {
5661
this.timeout(0);
62+
var result = false;
5763

5864
var app = spawn(execPath, [path.join('tmp-nw', 'app.nw')]);
5965
app.on('exit', function() {
66+
result = true;
6067
done();
6168
});
62-
setTimeout(function(){
63-
done('timeout');
64-
app.kill();
69+
setTimeout(function() {
70+
if (!result) {
71+
done('timeout');
72+
app.kill();
73+
}
6574
}, 10000);
6675

6776
})
6877

6978

7079
it('start from an executable file app.exe', function(done) {
7180
this.timeout(0);
72-
81+
var result = false;
7382

7483
if (os.platform() == 'win32') {
7584
execPath = path.join('tmp-nw', 'app.exe');
@@ -85,12 +94,15 @@ describe('different method of starting app (long-to-run)', function() {
8594
}
8695
var app = spawn(execPath);
8796
app.on('exit', function() {
97+
result = true;
8898
done();
8999
});
90100

91-
setTimeout(function(){
92-
done('timeout');
93-
app.kill();
101+
setTimeout(function() {
102+
if (!result) {
103+
done('timeout');
104+
app.kill();
105+
}
94106
}, 10000);
95107

96108
})

0 commit comments

Comments
 (0)