[Pkg-javascript-commits] [node-jsonfile] 01/03: New upstream version 3.0.1
Julien Puydt
julien.puydt at laposte.net
Tue Jul 11 08:19:13 UTC 2017
This is an automated email from the git hooks/post-receive script.
jpuydt-guest pushed a commit to branch master
in repository node-jsonfile.
commit 7d15d2685a3d581a01660f0608a478c1b7fae31f
Author: Julien Puydt <julien.puydt at laposte.net>
Date: Tue Jul 11 09:19:13 2017 +0200
New upstream version 3.0.1
---
CHANGELOG.md | 5 +++++
index.js | 4 +++-
package.json | 3 +--
test/read-file-sync.test.js | 11 -----------
test/read-file.test.js | 14 --------------
test/write-file-sync.test.js | 12 ------------
test/write-file.test.js | 25 ++++++++++++++-----------
7 files changed, 23 insertions(+), 51 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 70cf7c5..ff0c4e3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+3.0.1 / 2017-07-05
+------------------
+
+- Fixed bug in `writeFile` when there was a serialization error & no callback was passed. In previous versions, an empty file would be written; now no file is written.
+
3.0.0 / 2017-04-25
------------------
diff --git a/index.js b/index.js
index 5ac06cf..a28684f 100644
--- a/index.js
+++ b/index.js
@@ -94,7 +94,9 @@ function writeFile (file, obj, options, callback) {
try {
str = JSON.stringify(obj, options ? options.replacer : null, spaces) + '\n'
} catch (err) {
- if (callback) return callback(err, null)
+ // Need to return whether a callback was passed or not
+ if (callback) callback(err, null)
+ return
}
fs.writeFile(file, str, options, callback)
diff --git a/package.json b/package.json
index 7dfb90b..52719ed 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "jsonfile",
- "version": "3.0.0",
+ "version": "3.0.1",
"description": "Easily read/write JSON files.",
"repository": {
"type": "git",
@@ -22,7 +22,6 @@
},
"devDependencies": {
"mocha": "2.x",
- "mock-fs": "^3.8.0",
"rimraf": "^2.4.0",
"standard": "^6.0.8"
},
diff --git a/test/read-file-sync.test.js b/test/read-file-sync.test.js
index 2208de9..906e299 100644
--- a/test/read-file-sync.test.js
+++ b/test/read-file-sync.test.js
@@ -1,6 +1,5 @@
var assert = require('assert')
var fs = require('fs')
-var mockfs = require('mock-fs')
var os = require('os')
var path = require('path')
var rimraf = require('rimraf')
@@ -168,16 +167,6 @@ describe('+ readFileSync()', function () {
})
})
- describe('mockfs', function () {
- it('should read from a mockfs', function () {
- var mfs = mockfs.fs()
- var dataOut = {name: 'JP'}
- mfs.writeFileSync('test.json', JSON.stringify(dataOut), 'utf8')
- var dataIn = jf.readFileSync('test.json', { fs: mfs })
- assert.deepEqual(dataOut, dataIn)
- })
- })
-
describe('> w/ BOM', function () {
it('should properly parse', function () {
var file = path.join(TEST_DIR, 'file-bom.json')
diff --git a/test/read-file.test.js b/test/read-file.test.js
index 5de9832..9777e62 100644
--- a/test/read-file.test.js
+++ b/test/read-file.test.js
@@ -1,6 +1,5 @@
var assert = require('assert')
var fs = require('fs')
-var mockfs = require('mock-fs')
var os = require('os')
var path = require('path')
var rimraf = require('rimraf')
@@ -219,19 +218,6 @@ describe('+ readFile()', function () {
})
})
- describe('mockfs', function () {
- it('should read from a mockfs', function (done) {
- var mfs = mockfs.fs()
- var dataOut = {name: 'JP'}
- mfs.writeFileSync('test.json', JSON.stringify(dataOut), 'utf8')
- jf.readFile('test.json', { fs: mfs }, function (err, dataIn) {
- assert.ifError(err)
- assert.deepEqual(dataOut, dataIn)
- done()
- })
- })
- })
-
describe('> w/ BOM', function () {
it('should properly parse', function (done) {
var file = path.join(TEST_DIR, 'file-bom.json')
diff --git a/test/write-file-sync.test.js b/test/write-file-sync.test.js
index 0b6ff6b..0905061 100644
--- a/test/write-file-sync.test.js
+++ b/test/write-file-sync.test.js
@@ -1,6 +1,5 @@
var assert = require('assert')
var fs = require('fs')
-var mockfs = require('mock-fs')
var os = require('os')
var path = require('path')
var rimraf = require('rimraf')
@@ -90,15 +89,4 @@ describe('+ writeFileSync()', function () {
assert.strictEqual(data, JSON.stringify(obj) + '\n')
})
})
-
- describe('mockfs', function () {
- it('should write to mockfs', function () {
- var mfs = mockfs.fs()
- var dataOut = { name: 'JP' }
- var file = 'somefile.json'
- jf.writeFileSync(file, dataOut, { fs: mfs })
- var dataIn = JSON.parse(mfs.readFileSync(file, 'utf8'))
- assert.deepEqual(dataOut, dataIn)
- })
- })
})
diff --git a/test/write-file.test.js b/test/write-file.test.js
index 183a6a5..6eb1d31 100644
--- a/test/write-file.test.js
+++ b/test/write-file.test.js
@@ -1,6 +1,5 @@
var assert = require('assert')
var fs = require('fs')
-var mockfs = require('mock-fs')
var os = require('os')
var path = require('path')
var rimraf = require('rimraf')
@@ -120,17 +119,21 @@ describe('+ writeFile()', function () {
})
})
- describe('mockfs', function () {
- it('should write to mockfs', function (done) {
- var mfs = mockfs.fs()
- var dataOut = { name: 'JP' }
- var file = 'somefile.json'
- jf.writeFile(file, dataOut, { fs: mfs }, function (err) {
- assert.ifError(err)
- var dataIn = JSON.parse(mfs.readFileSync(file, 'utf8'))
- assert.deepEqual(dataOut, dataIn)
+ // Prevent https://github.com/jprichardson/node-jsonfile/issues/81 from happening
+ describe("> when callback isn't passed & can't serialize", function () {
+ it('should not write an empty file', function (done) {
+ this.slow(1100)
+ var file = path.join(TEST_DIR, 'somefile.json')
+ var obj1 = { name: 'JP' }
+ var obj2 = { person: obj1 }
+ obj1.circular = obj2
+
+ jf.writeFile(file, obj1)
+
+ setTimeout(function () {
+ assert(!fs.existsSync(file))
done()
- })
+ }, 1000)
})
})
})
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-jsonfile.git
More information about the Pkg-javascript-commits
mailing list