Emit 'warning' event for non-critical problems #2032

This commit is contained in:
Lovell Fuller
2020-06-12 13:46:12 +01:00
parent 8f5495a446
commit 19980190f7
3 changed files with 19 additions and 2 deletions

View File

@@ -19,11 +19,17 @@ describe('failOnError', function () {
});
});
it('handles truncated PNG', function (done) {
it('handles truncated PNG, emits warnings', function (done) {
let isWarningEmitted = false;
sharp(fixtures.inputPngTruncated, { failOnError: false })
.on('warning', function (warning) {
assert.strictEqual('not enough data', warning);
isWarningEmitted = true;
})
.resize(320, 240)
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(true, isWarningEmitted);
assert.strictEqual('png', info.format);
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);