@@ -3,11 +3,11 @@ var execPath = func.getExecPath();
3
3
var fs = require ( 'fs-extra' ) ;
4
4
var os = require ( 'os' ) ;
5
5
var spawn = require ( 'child_process' ) . spawn ;
6
+ var exec = require ( 'child_process' ) . exec ;
6
7
7
8
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' ) ;
11
11
function make_execuable_file ( folder_path , done ) {
12
12
func . copyExecFiles ( function ( ) {
13
13
func . copySourceFiles ( folder_path ) ;
@@ -65,67 +65,115 @@ describe('single-instance', function() {
65
65
before ( function ( done ) {
66
66
make_execuable_file ( 'single_instance/mul' , done ) ;
67
67
} ) ;
68
-
69
- after ( function ( ) {
68
+
69
+ after ( function ( ) {
70
70
fs . remove ( 'tmp-nw' , function ( er ) {
71
- if ( er ) throw er ;
72
- } ) ;
73
- } ) ;
74
-
71
+ if ( er ) throw er ;
72
+ } ) ;
73
+ } ) ;
74
+
75
75
it ( 'should have a instance' , function ( done ) {
76
76
check_have ( 0 , execPath , "" , 'not have a instance' , 0 , done ) ;
77
77
} ) ;
78
78
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
-
85
79
it ( 'should have a second instance' , function ( done ) {
86
80
check_have ( 1 , execPath , "" , 'not have a second instance' , 1 , done ) ;
87
81
} ) ;
82
+ } ) ;
88
83
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
-
96
84
97
85
describe ( 'single-instance default' , function ( ) {
98
86
99
87
before ( function ( done ) {
100
88
setTimeout ( function ( ) {
101
89
make_execuable_file ( 'single_instance/single' , done ) ;
102
- } , 2000 ) ;
90
+ } , 3000 ) ;
103
91
} ) ;
104
92
105
- after ( function ( ) {
93
+ after ( function ( ) {
106
94
fs . remove ( 'tmp-nw' , function ( er ) {
107
- if ( er ) throw er ;
108
- } ) ;
109
- } ) ;
95
+ if ( er ) throw er ;
96
+ } ) ;
97
+ } ) ;
110
98
111
99
it ( 'should have a instance' , function ( done ) {
112
100
check_have ( 2 , execPath , "" , 'not have a instance' , 0 , done ) ;
113
101
} ) ;
114
102
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
-
121
103
it ( 'should not have a second instance' , function ( done ) {
122
104
check_have ( 3 , execPath , "" , 'have a second instance' , 2 , done ) ;
123
105
} ) ;
106
+ } ) ;
124
107
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
+ } ) ;
128
177
} ) ;
129
178
}
130
- } ) ;
131
179
} ) ;
0 commit comments