@@ -3,65 +3,102 @@ var app_test = require('./nw_test_app');
3
3
var os = require ( 'os' ) ;
4
4
var fs = require ( 'fs-extra' ) ;
5
5
var cp = require ( 'child_process' ) ;
6
+ var snapshotPath ;
6
7
7
8
describe ( 'snapshot' , function ( ) {
8
9
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
+ }
20
22
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 ) ;
23
25
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
+ }
30
32
31
- ) ;
32
- } )
33
+ ) ;
34
+ } )
33
35
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
+ } )
38
40
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 ;
43
45
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
+ } ) ;
53
55
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);});
63
65
66
+ } )
64
67
} )
65
68
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
+
66
103
67
104
} )
0 commit comments