diff --git a/lib/renderer/png.js b/lib/renderer/png.js index 0bd15c7b..27421608 100644 --- a/lib/renderer/png.js +++ b/lib/renderer/png.js @@ -58,9 +58,16 @@ exports.renderToFile = function renderToFile (path, qrData, options, cb) { options = undefined } + let called = false + const done = (...args) => { + if (called) return + called = true + cb.apply(null, args) + } const stream = fs.createWriteStream(path) - stream.on('error', cb) - stream.on('close', cb) + + stream.on('error', done) + stream.on('close', done) exports.renderToFileStream(stream, qrData, options) } diff --git a/lib/renderer/utils.js b/lib/renderer/utils.js index 2d216919..87239dc5 100644 --- a/lib/renderer/utils.js +++ b/lib/renderer/utils.js @@ -39,7 +39,9 @@ exports.getOptions = function getOptions (options) { const margin = typeof options.margin === 'undefined' || options.margin === null || - options.margin < 0 ? 4 : options.margin + options.margin < 0 + ? 4 + : options.margin const width = options.width && options.width >= 21 ? options.width : undefined const scale = options.scale || 4 diff --git a/package.json b/package.json index 5ad92b7f..f3fd931d 100644 --- a/package.json +++ b/package.json @@ -58,8 +58,8 @@ "rollup-plugin-babel": "^4.4.0", "rollup-plugin-terser": "^5.3.0", "sinon": "^9.0.2", - "standard": "^14.3.3", - "tap": "^14.10.7" + "standard": "^16.0.4", + "tap": "^15.1.2" }, "repository": { "type": "git", @@ -71,7 +71,8 @@ "standard": { "ignore": [ "build/", - "examples/vendors/" + "examples/vendors/", + "lib/core/regex.js" ] } } diff --git a/test/e2e/toFile.test.js b/test/e2e/toFile.test.js index 0b8c2986..2cd58ec7 100644 --- a/test/e2e/toFile.test.js +++ b/test/e2e/toFile.test.js @@ -56,7 +56,7 @@ test('toFile png', function (t) { 'qVO5LQqTxRrFGKNUqxRon/scYo1ijFGqVYoxRrlGKNUqxRijVKsUYp1ijFGqVYoxRrlGKN', 'UqxRijXKP0OHEepgrecVAAAAAElFTkSuQmCC'].join('') - t.plan(9) + t.plan(8) QRCode.toFile(fileName, 'i am a pony!', { errorCorrectionLevel: 'L' diff --git a/test/unit/renderer/png.test.js b/test/unit/renderer/png.test.js index 6117923d..ecf910a7 100644 --- a/test/unit/renderer/png.test.js +++ b/test/unit/renderer/png.test.js @@ -92,7 +92,7 @@ test('PNG renderToFile', function (t) { let fsStub = sinon.stub(fs, 'createWriteStream') fsStub.returns(new StreamMock()) - t.plan(6) + t.plan(5) PngRenderer.renderToFile(fileName, sampleQrData, function (err) { t.ok(!err,