diff --git a/CHANGELOG.md b/CHANGELOG.md index fceec97..4126ca1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Change Log +## [Unreleased][Unreleased] + +### Added + +* CLI option `-S/--snapshots` to set a custom snapshots directory. + +### Fixed + +* Fix plural resources: DELETE should return 404 if resource doesn't exist. + ## [0.8.1][2015-10-06] ### Fixed diff --git a/src/cli/index.js b/src/cli/index.js index a7b44b4..92cf548 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -32,6 +32,11 @@ module.exports = function () { alias: 's', description: 'Set static files directory' }, + snapshots: { + alias: 'S', + description: 'Set snapshots directory', + default: '.' + }, delay: { alias: 'd', description: 'Add delay to responses (ms)' diff --git a/src/cli/run.js b/src/cli/run.js index 2af560a..25d8b01 100644 --- a/src/cli/run.js +++ b/src/cli/run.js @@ -117,7 +117,8 @@ module.exports = function (argv) { process.stdin.setEncoding('utf8') process.stdin.on('data', function (chunk) { if (chunk.trim().toLowerCase() === 's') { - var file = 'db-' + Date.now() + '.json' + var filename = 'db-' + Date.now() + '.json' + var file = path.join(argv.snapshots, filename) app.db.saveSync(file) console.log(' Saved snapshot to ' + file + '\n') } diff --git a/test/cli/index.js b/test/cli/index.js index c8c9683..7c3f25e 100644 --- a/test/cli/index.js +++ b/test/cli/index.js @@ -2,6 +2,7 @@ var os = require('os') var fs = require('fs') var path = require('path') var cp = require('child_process') +var assert = require('assert') var request = require('supertest') var rmrf = require('rimraf') var serverReady = require('server-ready') @@ -18,8 +19,8 @@ var routesFile = path.join(tmpDir, 'routes.json') function cli (args) { var bin = path.join(__dirname, '../..', pkg.bin) return cp.spawn('node', [bin, '-p', PORT].concat(args), { - stdio: 'inherit', - cwd: __dirname + cwd: __dirname, + stdio: ['pipe', process.stdout, process.stderr] }) } @@ -30,6 +31,7 @@ describe('cli', function () { var child beforeEach(function () { + rmrf.sync(tmpDir) fs.mkdirSync(tmpDir) fs.writeFileSync(dbFile, JSON.stringify({ posts: [{ 'id': 1, '_id': 2 }] })) fs.writeFileSync(routesFile, JSON.stringify({ '/blog/': '/' })) @@ -111,17 +113,29 @@ describe('cli', function () { }) - describe('db.json -s fixtures/public', function () { + describe('db.json -s fixtures/public -S ../../tmp', function () { + + var snapshotsDir = path.join(tmpDir, 'snapshots') + var publicDir = 'fixtures/public' beforeEach(function (done) { - child = cli([dbFile, '-s', 'fixtures/public']) - serverReady(PORT, done) + fs.mkdirSync(snapshotsDir) + child = cli([dbFile, '-s', publicDir, '-S', snapshotsDir]) + serverReady(PORT, function () { + child.stdin.write('s\n') + setTimeout(done, 100) + }) }) it('should serve fixtures/public', function (done) { request.get('/').expect(/Hello/, done) }) + it('should save a snapshot in ../../tmp', function () { + console.log(fs.readdirSync(snapshotsDir), fs.readdirSync(snapshotsDir).length) + assert.equal(fs.readdirSync(snapshotsDir).length, 1) + }) + }) // FIXME test fails on OS X and maybe on Windows