Skip to content

Commit 16612d6

Browse files
committed
Test case for single-instance with open method in Mac
1 parent 982e916 commit 16612d6

File tree

5 files changed

+131
-37
lines changed

5 files changed

+131
-37
lines changed

tests/automatic_tests/single_instance/mocha_test.js

Lines changed: 85 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ var execPath = func.getExecPath();
33
var fs = require('fs-extra');
44
var os = require('os');
55
var spawn = require('child_process').spawn;
6+
var exec = require('child_process').exec;
67

78
var app = new Array();
8-
9-
var mac_app_path = path.join('tmp-nw', 'node-webkit.app')
10-
9+
var child1, child2;
10+
var mac_app_path = path.join('tmp-nw', 'node-webkit.app');
1111
function make_execuable_file(folder_path, done) {
1212
func.copyExecFiles(function() {
1313
func.copySourceFiles(folder_path);
@@ -65,67 +65,115 @@ describe('single-instance', function() {
6565
before(function(done) {
6666
make_execuable_file('single_instance/mul', done);
6767
});
68-
69-
after(function() {
68+
69+
after(function() {
7070
fs.remove('tmp-nw', function (er) {
71-
if (er) throw er;
72-
});
73-
});
74-
71+
if (er) throw er;
72+
});
73+
});
74+
7575
it('should have a instance', function(done) {
7676
check_have(0, execPath, "", 'not have a instance', 0, done);
7777
});
7878

79-
if (os.platform() == 'darwin') {
80-
it('should have a instance (open app)', function(done) {
81-
check_have(4, 'open', [mac_app_path], 'not have a instance', 0, done);
82-
});
83-
}
84-
8579
it('should have a second instance', function(done) {
8680
check_have(1, execPath, "", 'not have a second instance', 1, done);
8781
});
82+
});
8883

89-
if (os.platform() == 'darwin') {
90-
it('should have a second instance (open app)', function(done) {
91-
check_have(5, 'open', [mac_app_path], 'not have a second instance', 1, done);
92-
});
93-
}
94-
})
95-
9684

9785
describe('single-instance default', function() {
9886

9987
before(function(done) {
10088
setTimeout(function() {
10189
make_execuable_file('single_instance/single', done);
102-
}, 2000);
90+
}, 3000);
10391
});
10492

105-
after(function() {
93+
after(function() {
10694
fs.remove('tmp-nw', function (er) {
107-
if (er) throw er;
108-
});
109-
});
95+
if (er) throw er;
96+
});
97+
});
11098

11199
it('should have a instance', function(done) {
112100
check_have(2, execPath, "", 'not have a instance', 0, done);
113101
});
114102

115-
if (os.platform() == 'darwin') {
116-
it('should have a instance (open app)', function(done) {
117-
check_have(6, 'open', [mac_app_path], 'not have a instance', 0, done);
118-
});
119-
}
120-
121103
it('should not have a second instance', function(done) {
122104
check_have(3, execPath, "", 'have a second instance', 2, done);
123105
});
106+
});
124107

125-
if (os.platform() == 'darwin') {
126-
it('should not have a second instance (open app)', function(done) {
127-
check_have(7, 'open', [mac_app_path], 'have a second instance', 2, done);
108+
if (os.platform() == 'darwin') {
109+
describe('single-instance false(open app)', function(){
110+
before(function(done) {
111+
setTimeout(function() {
112+
make_execuable_file('single_instance/open_mul', done);
113+
}, 3000);
114+
});
115+
116+
after(function() {
117+
fs.remove('tmp-nw', function (er) {
118+
if (er) throw er;
119+
});
120+
});
121+
122+
it('should have a instance (open app)', function(done) {
123+
child1 = exec('open ' + mac_app_path);
124+
setTimeout(function () {
125+
var content = fs.readFileSync('tmp-nw/msg');
126+
if (content + "" != "")
127+
done();
128+
else
129+
done("not have a instance");
130+
}, 6000);
131+
});
132+
133+
it('should have a second instance (open app)', function(done) {
134+
child2 = exec('open ' + mac_app_path);
135+
var content = fs.readFileSync('tmp-nw/msg');
136+
if (content + "" == "11")
137+
done();
138+
else
139+
done("not have a instance");
140+
});
141+
142+
});
143+
144+
describe('single-instance default(open app)', function(){
145+
before(function(done) {
146+
setTimeout(function() {
147+
make_execuable_file('single_instance/open_single', done);
148+
}, 3000);
149+
});
150+
151+
after(function() {
152+
fs.remove('tmp-nw', function (er) {
153+
if (er) throw er;
154+
});
155+
});
156+
157+
it('should have a instance (open app)', function(done) {
158+
child1 = exec('open ' + mac_app_path);
159+
setTimeout(function () {
160+
var content = fs.readFileSync('tmp-nw/msg_s');
161+
if (content + "" != "")
162+
done();
163+
else
164+
done("not have a instance");
165+
}, 6000);
166+
});
167+
168+
it('should not have a second instance (open app)', function(done) {
169+
child2 = exec('open ' + mac_app_path);
170+
var content = fs.readFileSync('tmp-nw/msg_s');
171+
if (content + "" == "11")
172+
done("have a second instance");
173+
else
174+
done();
175+
176+
});
128177
});
129178
}
130-
});
131179
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>open Mul-instance</title>
5+
</head>
6+
<body>
7+
<h1>open Mul-instance</h1>
8+
We are using node.js
9+
<script>
10+
var gui = require('nw.gui');
11+
var fs = require('fs');
12+
fs.appendFileSync('msg', '1');
13+
setTimeout(function() {
14+
gui.App.quit();
15+
}, 2000);
16+
17+
</script>
18+
</body>
19+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "nw-single-sinstance",
3+
"main": "index.html",
4+
"single-instance": false
5+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>open Single-instance</title>
5+
</head>
6+
<body>
7+
<h1>open Single-instance</h1>
8+
We are using node.js
9+
<script>
10+
var gui = require('nw.gui');
11+
var fs = require('fs');
12+
fs.appendFileSync('msg_s', '1');
13+
setTimeout(function() {
14+
gui.App.quit();
15+
}, 2000);
16+
</script>
17+
</body>
18+
</html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "nw-single-sinstance",
3+
"main": "index.html"
4+
}

0 commit comments

Comments
 (0)