Skip to content

Commit be56582

Browse files
committed
Merge pull request nwjs#1315 from kingFighter/tests
[test] Update test case for snapshot
2 parents db140a9 + 54eaea9 commit be56582

File tree

5 files changed

+130
-47
lines changed

5 files changed

+130
-47
lines changed

tests/automatic_tests/snapshot/mocha_test.js

Lines changed: 84 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,102 @@ var app_test = require('./nw_test_app');
33
var os = require('os');
44
var fs = require('fs-extra');
55
var cp = require('child_process');
6+
var snapshotPath;
67

78
describe('snapshot', function() {
89

9-
before(function(done) {
10-
var snapshotExec;
11-
if (os.platform() == 'darwin') {
12-
snapshotExec = '../../../../../../nwsnapshot';
13-
}
14-
if (os.platform() == 'linux') {
15-
snapshotExec = 'nwsnapshot';
16-
}
17-
if (os.platform() == 'win32') {
18-
snapshotExec = 'nwsnapshot.exe';
19-
}
10+
describe('demo should work fine', function() {
11+
before(function(done) {
12+
var snapshotExec;
13+
if (os.platform() == 'darwin') {
14+
snapshotExec = '../../../../../../nwsnapshot';
15+
}
16+
if (os.platform() == 'linux') {
17+
snapshotExec = 'nwsnapshot';
18+
}
19+
if (os.platform() == 'win32') {
20+
snapshotExec = 'nwsnapshot.exe';
21+
}
2022

21-
var snapshotPath = path.join(process.execPath, '..', snapshotExec);
22-
console.log("snapshotPath: " + snapshotPath);
23+
snapshotPath = path.join(process.execPath, '..', snapshotExec);
24+
console.log("snapshotPath: " + snapshotPath);
2325

24-
cp.execFile(snapshotPath,
25-
['--extra_code', 'mytest.js', 'mytest.bin'],
26-
{cwd:'./' + global.tests_dir + '/snapshot/'},
27-
function (error, stdout, stderr) {
28-
done();
29-
}
26+
cp.execFile(snapshotPath,
27+
['--extra_code', 'mytest.js', 'mytest.bin'],
28+
{cwd:'./' + global.tests_dir + '/snapshot/'},
29+
function (error, stdout, stderr) {
30+
done();
31+
}
3032

31-
);
32-
})
33+
);
34+
})
3335

34-
after(function() {
35-
fs.unlink(path.join(global.tests_dir, 'snapshot', 'mytest.bin'), function(err) {if(err && err.code !== 'ENOENT') throw err});
36-
fs.unlink(path.join(global.tests_dir, 'snapshot', 'v8.log'), function(err) {if(err && err.code !== 'ENOENT') throw err});
37-
})
36+
after(function() {
37+
fs.unlink(path.join(global.tests_dir, 'snapshot', 'mytest.bin'), function(err) {if(err && err.code !== 'ENOENT') throw err});
38+
fs.unlink(path.join(global.tests_dir, 'snapshot', 'v8.log'), function(err) {if(err && err.code !== 'ENOENT') throw err});
39+
})
3840

39-
it('the native code could be exectuted',
40-
function(done) {
41-
this.timeout(0);
42-
var result = false;
41+
it('the native code could be exectuted',
42+
function(done) {
43+
this.timeout(0);
44+
var result = false;
4345

44-
var child = app_test.createChildProcess({
45-
execPath: process.execPath,
46-
appPath: path.join(global.tests_dir, 'snapshot'),
47-
end: function(data, app) {
48-
done();
49-
app.kill();
50-
result = true;
51-
}
52-
});
46+
var child = app_test.createChildProcess({
47+
execPath: process.execPath,
48+
appPath: path.join(global.tests_dir, 'snapshot'),
49+
end: function(data, app) {
50+
done();
51+
app.kill();
52+
result = true;
53+
}
54+
});
5355

54-
setTimeout(function(){
55-
if (!result) {
56-
done('the native code does not been executed');
57-
child.close();
58-
//child.removeConnection();
59-
//child.app.kill();
60-
}
61-
}, 3000);
62-
//child.app.stderr.on('data', function(d){ console.log ('app' + d);});
56+
setTimeout(function(){
57+
if (!result) {
58+
done('the native code does not been executed');
59+
child.close();
60+
//child.removeConnection();
61+
//child.app.kill();
62+
}
63+
}, 3000);
64+
//child.app.stderr.on('data', function(d){ console.log ('app' + d);});
6365

66+
})
6467
})
6568

69+
describe('another demo should work fine', function() {
70+
before(function(done) {
71+
cp.execFile(snapshotPath,
72+
['--extra_code', 'file_to_snapshot_to_app.bin.js', 'app.bin'],
73+
{cwd:'./' + global.tests_dir + '/snapshot/test-snapshot-app/'},
74+
function (error, stdout, stderr) {
75+
done();
76+
}
77+
78+
);
79+
})
80+
81+
after(function() {
82+
fs.unlink(path.join(global.tests_dir, 'snapshot','test-snapshot-app', 'app.bin'), function(err) {if(err && err.code !== 'ENOENT') throw err});
83+
fs.unlink(path.join(global.tests_dir, 'snapshot','test-snapshot-app', 'v8.log'), function(err) {if(err && err.code !== 'ENOENT') throw err});
84+
fs.unlink(path.join(global.tests_dir, 'snapshot','test-snapshot-app','tmp'), function(err) {if(err && err.code !== 'ENOENT') throw err});
85+
})
86+
87+
it('another demo should close nomally', function(done) {
88+
this.timeout(0);
89+
var ppath = process.execPath + " " + path.join(global.tests_dir, 'snapshot', 'test-snapshot-app');
90+
cp.exec(ppath, function(err, stdout, stderr) {
91+
});
92+
setTimeout(function(){
93+
fs.exists(path.join(global.tests_dir, 'snapshot','test-snapshot-app', 'tmp'), function(exists) {
94+
if (exists)
95+
done();
96+
else
97+
done('another demo fails');
98+
});
99+
}, 3000);
100+
});
101+
});
102+
66103

67104
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var sampleFunction;
2+
3+
(function()
4+
{
5+
var privateVar = 'private';
6+
7+
sampleFunction = function()
8+
{
9+
return privateVar+'67868';
10+
};
11+
})();
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+
<meta charset="utf-8" />
5+
<title>snapshot test</title>
6+
<style>
7+
#content
8+
{
9+
font:10px Verdana;
10+
}
11+
</style>
12+
</head>
13+
<body>
14+
<div id="content">Data...</div>
15+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
16+
<script src="script.js"></script>
17+
<script>
18+
var fs = require('fs');
19+
fs.openSync('./tmp', 'w')
20+
setTimeout(function() {
21+
var gui = require('nw.gui');
22+
gui.App.quit();
23+
}, 2000);
24+
</script>
25+
</body>
26+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "nw-demo",
3+
"main": "index.html",
4+
"snapshot" : "app.bin"
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$(document).ready(function()
2+
{
3+
$('#content').html(sampleFunction());
4+
});

0 commit comments

Comments
 (0)