🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →

json-file-plus

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-file-plus - npm Package Compare versions

Comparing version

to
1.0.0

{
"name": "json-file-plus",
"version": "0.2.3",
"version": "1.0.0",
"author": "Jordan Harband",

@@ -9,3 +9,6 @@ "description": "Read from and write to a JSON file, minimizing diffs and preserving formatting.",

"scripts": {
"test": "node test/test.js"
"test": "npm run lint && node test/test.js",
"coverage": "covert test/test.js",
"coverage-quiet": "covert test/test.js --quiet",
"lint": "jscs *.js test/*.js"
},

@@ -24,11 +27,16 @@ "repository": {

"dependencies": {
"is": "~0.2.6",
"node.extend": "~1.0.8"
"is": "~0.3.0",
"jscs": "~1.5.7",
"node.extend": "~1.0.10"
},
"devDependencies": {
"tape": "~2.3.0",
"tape": "~2.14.0",
"foreach": "~2.0.4",
"object-keys": "~0.4.0"
"object-keys": "~0.6.0",
"covert": "~0.4.0"
},
"engines": {
"node": ">= 0.4"
}
}

@@ -20,6 +20,17 @@ var test = require('tape');

test('requires a callback', function (t) {
t.plan(6);
t.throws(function () { jsonFile(testFilename); }, TypeError, 'requires a function');
t.throws(function () { jsonFile(testFilename, null); }, TypeError, 'requires a function');
t.throws(function () { jsonFile(testFilename, true); }, TypeError, 'requires a function');
t.throws(function () { jsonFile(testFilename, /a/g); }, TypeError, 'requires a function');
t.throws(function () { jsonFile(testFilename, []); }, TypeError, 'requires a function');
t.throws(function () { jsonFile(testFilename, {}); }, TypeError, 'requires a function');
t.end();
});
test('returns a file', function (t) {
t.plan(2);
jsonFile(testFilename, function (err, file) {
t.notOk(err, 'no error');
t.error(err, 'no error');
t.ok(file instanceof jsonFile.JSONFile, 'file is instance of JSONFile');

@@ -30,6 +41,32 @@ t.end();

test('returns an exception if the file is not found', function (t) {
t.plan(4);
jsonFile('NOT A REAL FILE', function (err, file) {
t.ok(err, 'error is truthy');
t.ok(err.errno === 34 || err.errno === -2, 'error number is correct');
var expectedError = {
errno: err.errno,
code: 'ENOENT',
path: 'NOT A REAL FILE'
};
t.deepEqual(err, expectedError, 'returns an error');
t.equal(file, undefined, 'file is undefined');
t.end();
});
});
test('returns an exception if the file has invalid JSON', function (t) {
t.plan(3);
jsonFile(__filename, function (err, file) {
t.ok(err instanceof SyntaxError, 'error is a SyntaxError');
t.equal(err.message, 'Unexpected token v', 'gives the expected error');
t.equal(file, undefined, 'file is undefined');
t.end();
});
});
test('format', function (t) {
t.plan(5);
jsonFile(testFilename, function (err, file) {
t.notOk(err, 'no error');
t.error(err, 'no error');
t.equal(file.format.indent, '\t', 'reads tabs');

@@ -45,3 +82,3 @@ t.equal(file.format.trailing, true, 'reads trailing newline');

jsonFile(noNewlineFilename, function (err, file) {
s1t.notOk(err, 'no error');
s1t.error(err, 'no error');
s1t.notOk(file.format.trailing, 'reads no trailing newline');

@@ -59,3 +96,3 @@ s1t.equal(file.format.indent, ' ', 'reads three spaces');

jsonFile(testFilename, function (err, file) {
st.notOk(err, 'no error');
st.error(err, 'no error');
st.deepEqual(file.data, testContents, 'file.data matches expected');

@@ -70,3 +107,3 @@ st.notEqual(file.get('obj'), file.data.obj, 'get(key)->object is not the same reference');

jsonFile(testFilename, function (err, file) {
st.notOk(err, 'no error');
st.error(err, 'no error');
forEach(testContents, function (keyContents, key) {

@@ -82,3 +119,3 @@ st.deepEqual(file.get(key), keyContents, 'data from get("' + key + '") matches');

jsonFile(testFilename, function (err, file) {
st.notOk(err, 'no error');
st.error(err, 'no error');
forEach(testContents, function (keyContents, key) {

@@ -95,3 +132,3 @@ file.get(key, function (err, data) {

jsonFile(testFilename, function (err, file) {
s2t.notOk(err, 'no error');
s2t.error(err, 'no error');
var getData = file.get();

@@ -107,3 +144,3 @@ s2t.deepEqual(getData, file.data, 'data from get() matches');

jsonFile(testFilename, function (err, file) {
s2t.notOk(err, 'no error');
s2t.error(err, 'no error');
file.get(function (err, data) {

@@ -120,3 +157,3 @@ s2t.deepEqual(data, file.data, 'data from async get() matches');

jsonFile(testFilename, function (err, file) {
t.notOk(err, 'no error');
t.error(err, 'no error');
t.equal(undefined, file.data.foobar, 'foo starts undefined');

@@ -140,3 +177,3 @@ var data = {

jsonFile(testFilename, function (err, file) {
st.notOk(err, 'no error');
st.error(err, 'no error');
var error = new TypeError('object must be a plain object');

@@ -154,7 +191,9 @@ st.throws(function () { return file.set(null); }, error, 'throws when given non-object');

test('returns an error when no file', function (t) {
t.plan(1);
t.plan(3);
var filename = path.join(process.cwd(), 'does not exist.json');
jsonFile(filename, function (err, file) {
t.ok(err, 'error is truthy');
t.ok(err.errno === 34 || err.errno === -2, 'error number is correct');
var expectedError = {
errno: 34,
errno: err.errno,
code: "ENOENT",

@@ -182,3 +221,3 @@ path: filename

file.save(function (err) {
t.notOk(err, 'no error');
t.error(err, 'no error');
jsonFile(testFilename, function (err, file2) {

@@ -188,3 +227,3 @@ t.equal(file2.get('foo'), !testContents.foo, 'value was properly saved');

file2.save(function (err) {
t.notOk(err, 'no error');
t.error(err, 'no error');
t.end();

@@ -191,0 +230,0 @@ });

Sorry, the diff of this file is not supported yet