@@ -2,6 +2,7 @@ var os = require('os')
22var fs = require ( 'fs' )
33var path = require ( 'path' )
44var cp = require ( 'child_process' )
5+ var assert = require ( 'assert' )
56var request = require ( 'supertest' )
67var rmrf = require ( 'rimraf' )
78var serverReady = require ( 'server-ready' )
@@ -18,8 +19,8 @@ var routesFile = path.join(tmpDir, 'routes.json')
1819function cli ( args ) {
1920 var bin = path . join ( __dirname , '../..' , pkg . bin )
2021 return cp . spawn ( 'node' , [ bin , '-p' , PORT ] . concat ( args ) , {
21- stdio : 'inherit' ,
22- cwd : __dirname
22+ cwd : __dirname ,
23+ stdio : [ 'pipe' , process . stdout , process . stderr ]
2324 } )
2425}
2526
@@ -30,6 +31,7 @@ describe('cli', function () {
3031 var child
3132
3233 beforeEach ( function ( ) {
34+ rmrf . sync ( tmpDir )
3335 fs . mkdirSync ( tmpDir )
3436 fs . writeFileSync ( dbFile , JSON . stringify ( { posts : [ { 'id' : 1 , '_id' : 2 } ] } ) )
3537 fs . writeFileSync ( routesFile , JSON . stringify ( { '/blog/' : '/' } ) )
@@ -111,17 +113,29 @@ describe('cli', function () {
111113
112114 } )
113115
114- describe ( 'db.json -s fixtures/public' , function ( ) {
116+ describe ( 'db.json -s fixtures/public -S ../../tmp' , function ( ) {
117+
118+ var snapshotsDir = path . join ( tmpDir , 'snapshots' )
119+ var publicDir = 'fixtures/public'
115120
116121 beforeEach ( function ( done ) {
117- child = cli ( [ dbFile , '-s' , 'fixtures/public' ] )
118- serverReady ( PORT , done )
122+ fs . mkdirSync ( snapshotsDir )
123+ child = cli ( [ dbFile , '-s' , publicDir , '-S' , snapshotsDir ] )
124+ serverReady ( PORT , function ( ) {
125+ child . stdin . write ( 's\n' )
126+ setTimeout ( done , 100 )
127+ } )
119128 } )
120129
121130 it ( 'should serve fixtures/public' , function ( done ) {
122131 request . get ( '/' ) . expect ( / H e l l o / , done )
123132 } )
124133
134+ it ( 'should save a snapshot in ../../tmp' , function ( ) {
135+ console . log ( fs . readdirSync ( snapshotsDir ) , fs . readdirSync ( snapshotsDir ) . length )
136+ assert . equal ( fs . readdirSync ( snapshotsDir ) . length , 1 )
137+ } )
138+
125139 } )
126140
127141 // FIXME test fails on OS X and maybe on Windows
0 commit comments