Skip to content

Commit aeb4b44

Browse files
committed
[test] different method of starting app
1 parent 6a756dc commit aeb4b44

File tree

7 files changed

+234
-1
lines changed

7 files changed

+234
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.DS_Store
22
tests/node_modules
3+
tests/native_modules
4+
tests/tmp-nw
35
*.pyc
46
*~
57
.*.sw?

tests/app_tests/start_app/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<html>
2+
<head>
3+
<title> Hello World </title>
4+
</head>
5+
<body>
6+
<script>
7+
var gui = require('nw.gui');
8+
//gui.Window.get().show();
9+
10+
gui.App.quit();
11+
12+
</script>
13+
<p>this is node-webkit</p>
14+
15+
</body>
16+
</html>
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
var spawn = require('child_process').spawn;
2+
var exec = require('child_process').exec;
3+
var path = require('path');
4+
var net = require('net');
5+
var os = require('os');
6+
var server = global.server;
7+
var func = require('./app_tests/start_app/script.js');
8+
var execPath = func.getExecPath();
9+
var fs = require('fs-extra');
10+
11+
describe('Startup', function() {
12+
describe('different method of starting app (long-to-run)', function() {
13+
var temp_root = 'tmp-nw';
14+
before(function(done){
15+
this.timeout(0);
16+
func.copyExecFiles();
17+
func.copySourceFiles();
18+
func.zipSourceFiles(function() {
19+
func.makeExecuableFile();
20+
done();
21+
});
22+
23+
})
24+
25+
26+
after(function() {
27+
setTimeout(function() {
28+
fs.remove('tmp-nw', function (er) {
29+
if (er) throw er;
30+
})
31+
}, 1000);
32+
})
33+
34+
35+
it('start from nw that package.json in the same folder', function(done) {
36+
this.timeout(0);
37+
38+
if (os.platform() == 'darwin') {
39+
//mac don't have this method
40+
done();
41+
return;
42+
}
43+
44+
var app = spawn(execPath);
45+
app.on('exit', function() {
46+
done();
47+
});
48+
setTimeout(function(){
49+
done('timeout');
50+
app.kill();
51+
}, 10000);
52+
53+
})
54+
55+
it('start from app.nw', function(done) {
56+
this.timeout(0);
57+
58+
var app = spawn(execPath, [path.join('tmp-nw', 'app.nw')]);
59+
app.on('exit', function() {
60+
done();
61+
});
62+
setTimeout(function(){
63+
done('timeout');
64+
app.kill();
65+
}, 10000);
66+
67+
})
68+
69+
70+
it('start from an executable file app.exe', function(done) {
71+
this.timeout(0);
72+
73+
74+
if (os.platform() == 'win32') {
75+
execPath = path.join('tmp-nw', 'app.exe');
76+
}
77+
if (os.platform() == 'linux') {
78+
execPath = path.join('tmp-nw', 'app');
79+
}
80+
if (os.platform() == 'darwin') {
81+
var app_path = 'tmp-nw/node-webkit.app/Contents/Resources/app.nw';
82+
fs.mkdir(app_path);
83+
fs.copy('tmp-nw/index.html', path.join(app_path, 'index.html'));
84+
fs.copy('tmp-nw/package.html', path.join(app_path, 'package.html'));
85+
}
86+
var app = spawn(execPath);
87+
app.on('exit', function() {
88+
done();
89+
});
90+
91+
setTimeout(function(){
92+
done('timeout');
93+
app.kill();
94+
}, 10000);
95+
96+
})
97+
98+
99+
})
100+
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "nw-demo",
3+
"version": "0.1.0",
4+
"main": "index.html",
5+
"window": {
6+
"show": false
7+
}
8+
}

tests/app_tests/start_app/script.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
var path = require('path');
2+
var os = require('os');
3+
var fs = require('fs-extra');
4+
var cp = require('child_process');
5+
var exec = cp.exec;
6+
var sqawn = cp.sqawn;
7+
8+
var required_file_win = [
9+
'ffmpegsumo.dll',
10+
'icudt.dll',
11+
'libEGL.dll',
12+
'libGLESv2.dll',
13+
'nw.exe',
14+
'nw.pak'
15+
];
16+
17+
var required_file_linux = [
18+
'nw',
19+
'nw.pak',
20+
'libffmpegsumo.so'
21+
];
22+
23+
var required_file_macox = [
24+
'node-webkit.app'
25+
];
26+
27+
var source_file = ['index.html', 'package.json'];
28+
29+
var exec_root = path.dirname(process.execPath);
30+
var required_file;
31+
if (os.platform() == 'win32') {
32+
required_file = required_file_win;
33+
}
34+
if (os.platform() == 'linux') {
35+
required_file = required_file_linux;
36+
}
37+
if (os.platform() == 'darwin') {
38+
required_file = required_file_macox;
39+
exec_root = path.normalize(
40+
path.join(exec_root, '..', '..', '..'));
41+
}
42+
43+
44+
45+
exports.getExecPath = function() {
46+
if (os.platform() == 'win32') {
47+
return path.join('tmp-nw', 'nw.exe');
48+
}
49+
if (os.platform() == 'linux') {
50+
return path.join('tmp-nw', 'nw');
51+
}
52+
if (os.platform() == 'darwin') {
53+
return path.join('tmp-nw', 'node-webkit.app', 'Contents', 'MacOS', 'node-webkit');
54+
}
55+
56+
}
57+
58+
function copyExecFiles() {
59+
fs.mkdir('tmp-nw');
60+
61+
for (var i in required_file) {
62+
var src_file = path.join(exec_root, required_file[i]);
63+
var dst_file = path.join('tmp-nw', required_file[i]);
64+
//fs.copyFileSync(src_file, dst_file);
65+
fs.copy(src_file, dst_file);
66+
}
67+
68+
}
69+
70+
exports.copySourceFiles = function() {
71+
fs.createReadStream('app_tests/start_app/index.html').pipe(fs.createWriteStream('tmp-nw/index.html'));
72+
fs.createReadStream('app_tests/start_app/package.json').pipe(fs.createWriteStream('tmp-nw/package.json'));
73+
}
74+
75+
exports.zipSourceFiles = function(callback) {
76+
exec('python app_tests/start_app/zip.py');
77+
setTimeout(callback, 2000);
78+
79+
}
80+
81+
exports.makeExecuableFile = function() {
82+
if (os.platform() == 'win32') {
83+
cp.exec('copy /b nw.exe+app.nw app.exe', {cwd: './tmp-nw/'});
84+
}
85+
if (os.platform() == 'linux') {
86+
cp.exec('cat nw app.nw > app && chmod +x app', {cwd: './tmp-nw/'});
87+
}
88+
89+
}
90+
91+
92+
exports.copyExecFiles = copyExecFiles;

tests/app_tests/start_app/zip.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import zipfile
2+
import os
3+
4+
zip = zipfile.ZipFile(os.path.join('tmp-nw', 'app.nw'), 'w',
5+
compression=zipfile.ZIP_DEFLATED)
6+
7+
source_file = ['index.html', 'package.json']
8+
9+
for file in source_file:
10+
path = os.path.join('tmp-nw', file)
11+
zip.write(path, file)
12+
13+
zip.close();
14+

tests/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"mocha": "1.7.4",
2121
"nw-gyp": "*",
2222
"nw_test_loop": "git+https://github.com/owenc4a4/nw_test_loop_without_handle.git",
23-
"bignum": "git+https://github.com/owenc4a4/bignum.git"
23+
"bignum": "git+https://github.com/owenc4a4/bignum.git",
24+
"fs-extra": "*"
2425
},
2526
"chromium-args": "--disable-javascript-i18n-api",
2627
"user-agent": "%name/%nwver/%ver/%webkit_ver/%osinfo",

0 commit comments

Comments
 (0)