Skip to content

Commit e13fa60

Browse files
committed
[test] temp dir should be removed after app exits
1 parent 2b7de41 commit e13fa60

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Test CASE FOR TMP DIR SHOULD BE REMOVED AFTER APP EXIT</title>
5+
</head>
6+
<body>
7+
<h1>Hello World!</h1>
8+
<script>
9+
var gui = require('nw.gui');
10+
var path = require('path');
11+
var temp_dir_path = location.href;
12+
var fs = require('fs');
13+
var tmp_path = path.join(gui.App.argv[0], 'tmp-nw', 'path.org');
14+
15+
fs.writeFile(tmp_path, temp_dir_path, function(err) {
16+
if(err) {
17+
console.log(err);
18+
} else {
19+
console.log("The file was saved!");
20+
gui.App.quit();
21+
}
22+
});
23+
24+
</script>
25+
</body>
26+
</html>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
var func = require('./' + global.tests_dir +'/start_app/script.js');
2+
var execPath = func.getExecPath();
3+
var fs = require('fs-extra');
4+
var os = require('os');
5+
var cp = require('child_process');
6+
var app_test = require('./nw_test_app');
7+
var current_path = process.cwd();
8+
var mac_app_path = path.join('tmp-nw', 'node-webkit.app');
9+
var assert = require('assert');
10+
var temp_path;
11+
var execPath;
12+
13+
if (os.platform() == 'win32') {
14+
execPath = path.join('tmp-nw', 'app.exe');
15+
}
16+
if (os.platform() == 'linux') {
17+
execPath = path.join('tmp-nw', 'app');
18+
}
19+
if (os.platform() == 'darwin') {
20+
execPath = path.join('tmp-nw', 'node-webkit.app', 'Contents', 'MacOS', 'node-webkit');
21+
}
22+
23+
function make_execuable_file(folder_path, done) {
24+
func.copyExecFiles(function() {
25+
func.copySourceFiles(folder_path);
26+
func.zipSourceFiles(function() {
27+
func.makeExecuableFile();
28+
if (os.platform() == 'darwin') {
29+
var app_path = 'tmp-nw/node-webkit.app/Contents/Resources/app.nw';
30+
fs.mkdir(app_path, function(err) {
31+
if(err && err.code !== 'EEXIST') throw err
32+
fs.copy('tmp-nw/index.html', path.join(app_path, 'index.html'));
33+
fs.copy('tmp-nw/package.html', path.join(app_path, 'package.html'));
34+
setTimeout(done, 3000);
35+
36+
});
37+
} else {
38+
setTimeout(function() {
39+
var child = cp.spawn(execPath, [current_path]);
40+
child.on('exit', function() {
41+
temp_path = path.dirname(fs.readFileSync(path.join('tmp-nw','path.org'))).substring(8);
42+
done();
43+
});
44+
}, 3000);
45+
}
46+
});
47+
});
48+
}
49+
50+
describe('temp_dir', function() {
51+
this.timeout(0);
52+
53+
before(function(done) {
54+
make_execuable_file('temp_dir', done);
55+
});
56+
57+
after(function() {
58+
fs.remove('tmp-nw', function (er) {
59+
if (er) throw er;
60+
});
61+
});
62+
63+
it('should be removed after app exit', function() {
64+
var exist = fs.existsSync(temp_path);
65+
assert.equal(exist, false);
66+
});
67+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "nw",
3+
"main": "index.html"
4+
}

0 commit comments

Comments
 (0)