forked from nwjs/nw.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmocha_test.js
138 lines (117 loc) · 3.19 KB
/
mocha_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
var spawn = require('child_process').spawn;
var exec = require('child_process').exec;
var path = require('path');
var net = require('net');
var os = require('os');
var fs = require('fs-extra');
var curDir = require('fs').realpathSync('.');
var func = require(path.join(curDir, 'script.js'));
var execPath = path.join(curDir, func.getExecPath());
describe('Startup', function() {
describe('different method of starting app (long-to-run)', function() {
before(function(done){
this.timeout(10000);
func.copyExecFiles(function() {
func.copySourceFiles('internal');
func.zipSourceFiles(function() {
func.makeExecuableFile();
done();
});
});
});
after(function(done) {
setTimeout(function() {
fs.remove(path.join(curDir, 'tmp-nw'), function (er) {
if (er) {
console.log('Failed to remove the temporary folder tmp-nw: ' + er);
throw er;
}
done();
})
}, 1000);
})
it('start from nw that package.json in the same folder', function(done) {
this.timeout(0);
var result = false;
if (os.platform() == 'darwin') {
//mac don't have this method
done();
return;
}
var app = spawn(execPath);
app.on('exit', function() {
result = true;
done();
});
setTimeout(function() {
if (!result) {
done('timeout');
app.kill();
}
}, 10000);
})
it('start from app.nw', function(done) {
this.timeout(0);
var result = false;
var app = spawn(execPath, [path.join(curDir, 'tmp-nw', 'app.nw')]);
app.on('exit', function() {
result = true;
done();
});
setTimeout(function() {
if (!result) {
done('timeout');
app.kill();
}
}, 10000);
})
it('start from folder contains `../`', function(done) {
this.timeout(0);
var result = false;
var app = spawn(execPath, [path.join(curDir, '..', '..', 'tmp-nw')]);
app.on('exit', function() {
result = true;
done();
});
setTimeout(function() {
if (!result) {
done('timeout');
app.kill();
}
}, 10000);
})
it('start from an executable file app.exe', function(done) {
this.timeout(0);
var result = false;
function launch(appPath) {
var app = spawn(appPath);
app.on('exit', function() {
result = true;
done();
});
setTimeout(function() {
if (!result) {
done('timeout');
app.kill();
}
}, 10000);
}
if (os.platform() == 'win32') {
launch(path.join(curDir, 'tmp-nw', 'app.exe'));
}
if (os.platform() == 'linux') {
launch(path.join(curDir, 'tmp-nw', 'app'));
}
if (os.platform() == 'darwin') {
var app_path = curDir + 'tmp-nw/node-webkit.app/Contents/Resources/app.nw';
fs.mkdir(app_path, function(err) {
if(err && err.code !== 'EEXIST') throw err
fs.copy(path.join(curDir, 'tmp-nw', 'internal', 'index.html'), path.join(app_path, 'index.html'));
fs.copy(path.join(curDir, 'tmp-nw', 'internal', 'package.json'), path.join(app_path, 'package.json'), function() {
launch(app_path);
});
});
}
})
})
})