Skip to content

Commit f0e6c9a

Browse files
committed
Add --snapshots and basic test
1 parent 94cfbab commit f0e6c9a

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Change Log
22

3+
## [Unreleased][Unreleased]
4+
5+
### Added
6+
7+
* CLI option `-S/--snapshots` to set a custom snapshots directory.
8+
9+
### Fixed
10+
11+
* Fix plural resources: DELETE should return 404 if resource doesn't exist.
12+
313
## [0.8.1][2015-10-06]
414

515
### Fixed

src/cli/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ module.exports = function () {
3232
alias: 's',
3333
description: 'Set static files directory'
3434
},
35+
snapshots: {
36+
alias: 'S',
37+
description: 'Set snapshots directory',
38+
default: '.'
39+
},
3540
delay: {
3641
alias: 'd',
3742
description: 'Add delay to responses (ms)'

src/cli/run.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ module.exports = function (argv) {
117117
process.stdin.setEncoding('utf8')
118118
process.stdin.on('data', function (chunk) {
119119
if (chunk.trim().toLowerCase() === 's') {
120-
var file = 'db-' + Date.now() + '.json'
120+
var filename = 'db-' + Date.now() + '.json'
121+
var file = path.join(argv.snapshots, filename)
121122
app.db.saveSync(file)
122123
console.log(' Saved snapshot to ' + file + '\n')
123124
}

test/cli/index.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var os = require('os')
22
var fs = require('fs')
33
var path = require('path')
44
var cp = require('child_process')
5+
var assert = require('assert')
56
var request = require('supertest')
67
var rmrf = require('rimraf')
78
var serverReady = require('server-ready')
@@ -18,8 +19,8 @@ var routesFile = path.join(tmpDir, 'routes.json')
1819
function 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(/Hello/, 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

Comments
 (0)