workshopper-adventure-storage
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "workshopper-adventure-storage", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,14 +7,20 @@ var storage = require('..') | ||
var fileName = './foo/bar/index.json' | ||
var testStorage | ||
var invalidJson = './foo/bar/invalid.json' | ||
var testStorage = storage('foo', 'bar') | ||
/** | ||
* Initialize storage and save a file. | ||
*/ | ||
before(function (done) { | ||
testStorage = storage('foo', 'bar') | ||
testStorage.save('index', { | ||
foo: 'bar' | ||
}, function (err) { | ||
beforeEach(function (done) { | ||
function writeBadJson (err) { | ||
if (err) return done(err) | ||
done() | ||
fs.writeFile(invalidJson, '{', done) | ||
} | ||
testStorage.reset(function (err) { | ||
if (err) return done(err) | ||
testStorage.save('index', { | ||
foo: 'bar' | ||
}, writeBadJson) | ||
}) | ||
@@ -28,29 +34,47 @@ }) | ||
it('should save serialized storage to the data directory', function (done) { | ||
fs.readFile(fileName, function (err, data) { | ||
if (err) return done(err) | ||
var fileData | ||
try { | ||
fileData = JSON.parse(data) | ||
} catch (e) { | ||
done(e) | ||
} | ||
done(null, fileData) | ||
describe('#save', function() { | ||
it('should save serialized storage to the data directory', function (done) { | ||
fs.readFile(fileName, function (err, data) { | ||
if (err) return done(err) | ||
var fileData | ||
try { | ||
fileData = JSON.parse(data) | ||
} catch (e) { | ||
done(e) | ||
} | ||
done() | ||
}) | ||
}) | ||
}) | ||
it('should retrive a stored file', function (done) { | ||
testStorage.get('index', function (err, file) { | ||
if (err) return done(err) | ||
expect(file.foo).to.equal('bar') | ||
done() | ||
describe('#get', function () { | ||
it('should retrive a stored file', function (done) { | ||
testStorage.get('index', function (err, file) { | ||
if (err) return done(err) | ||
expect(file.foo).to.equal('bar') | ||
done() | ||
}) | ||
}) | ||
it('handle invalid JSON', function (done) { | ||
fs.readFile(invalidJson, function (err, data) { | ||
if (err) return done(err) | ||
var fileData | ||
try { | ||
fileData = JSON.parse(data) | ||
} catch (e) { | ||
return done() | ||
} | ||
done('read the file!') | ||
}) | ||
}) | ||
}) | ||
it('should clean the storage directory', function (done) { | ||
testStorage.reset(function () { | ||
fs.stat('./foo/bar', function (err, stats) { | ||
if (err && err.code === 'ENOENT') return done() | ||
done('file still exists!') | ||
describe('#reset', function () { | ||
it('should clean the storage directory', function (done) { | ||
testStorage.reset(function () { | ||
fs.stat('./foo/bar', function (err, stats) { | ||
if (err && err.code === 'ENOENT') return done() | ||
done('file still exists!') | ||
}) | ||
}) | ||
@@ -57,0 +81,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8486
126