Skip to content

Commit 9c080c4

Browse files
committed
add new test case "temp_dir"
1 parent fa58d9e commit 9c080c4

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed

tests/automation/temp_dir/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>temp dir test</title>
6+
</head>
7+
<body>
8+
<p>temp dir test</p>
9+
10+
<script src="../res/mocha_util.js"></script>
11+
<script src="mocha_test.js"></script>
12+
13+
</body>
14+
15+
</html>
16+
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: 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+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
var path = require('path');
2+
var os = require('os');
3+
var cp = require('child_process');
4+
var assert = require('assert');
5+
var fs = require('fs-extra');
6+
var curDir = fs.realpathSync('.');
7+
8+
var func = require(path.join(curDir, '..', 'start_app', 'script.js'));
9+
var execPath = func.getExecPath();
10+
11+
12+
var mac_app_path = path.join(curDir, 'tmp-nw', 'node-webkit.app');
13+
14+
var temp_path;
15+
16+
if (os.platform() == 'win32') {
17+
execPath = path.join(curDir, 'tmp-nw', 'app.exe');
18+
} else if (os.platform() == 'linux') {
19+
execPath = path.join(curDir, 'tmp-nw', 'app');
20+
} else if (os.platform() == 'darwin') {
21+
execPath = path.join(curDir, 'tmp-nw', 'node-webkit.app', 'Contents', 'MacOS', 'node-webkit');
22+
}
23+
24+
function make_execuable_file(folder_path, done) {
25+
func.copyExecFiles(function() {
26+
func.copySourceFiles(folder_path);
27+
func.zipSourceFiles(function() {
28+
func.makeExecuableFile();
29+
if (os.platform() == 'darwin') {
30+
var app_path = 'tmp-nw/node-webkit.app/Contents/Resources/app.nw';
31+
fs.mkdir(app_path, function(err) {
32+
if(err && err.code !== 'EEXIST') throw err
33+
fs.copy('tmp-nw/index.html', path.join(app_path, 'index.html'));
34+
fs.copy('tmp-nw/package.html', path.join(app_path, 'package.html'));
35+
setTimeout(done, 3000);
36+
37+
});
38+
} else {
39+
setTimeout(function() {
40+
var child = cp.spawn(execPath, curDir); // [path.join(curDir, 'internal')]);
41+
child.on('exit', function() {
42+
temp_path = path.dirname(fs.readFileSync(path.join(curDir, 'tmp-nw','path.org'))).substring(8);
43+
done();
44+
});
45+
}, 3000);
46+
}
47+
});
48+
});
49+
}
50+
51+
describe('temp_dir', function() {
52+
this.timeout(0);
53+
54+
before(function(done) {
55+
make_execuable_file('internal', done);
56+
});
57+
58+
after(function() {
59+
fs.remove('tmp-nw', function (er) {
60+
if (er) throw er;
61+
});
62+
});
63+
64+
it('should be removed after app exit', function() {
65+
var exist = fs.existsSync(temp_path);
66+
assert.equal(exist, false);
67+
});
68+
});
69+
70+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name":"temp_dir_wrapper",
3+
"main":"index.html"
4+
}
5+

0 commit comments

Comments
 (0)