From 65049cfbba7652af3d9318ee8f42865c026799eb Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Sun, 22 Nov 2020 12:30:15 +0100 Subject: [PATCH] prettier --write '**/*.{js,json,md}' --- lib/unexpectedResemble.js | 181 +++++++++++++++++++------------------- 1 file changed, 92 insertions(+), 89 deletions(-) diff --git a/lib/unexpectedResemble.js b/lib/unexpectedResemble.js index a2accd4..4daa9c6 100644 --- a/lib/unexpectedResemble.js +++ b/lib/unexpectedResemble.js @@ -6,109 +6,112 @@ module.exports = { installInto(expect) { expect = expect.child().use(require('magicpen-media')); - expect.exportAssertion(' to resemble ', function ( - expect, - subject, - otherImage, - value - ) { - expect.subjectOutput = function () { - this.image(subject, { width: 10, height: 5, link: true }); - }; + expect.exportAssertion( + ' to resemble ', + function (expect, subject, otherImage, value) { + expect.subjectOutput = function () { + this.image(subject, { width: 10, height: 5, link: true }); + }; - expect.argsOutput[0] = function () { - this.image(otherImage, { width: 10, height: 5, link: true }); - }; + expect.argsOutput[0] = function () { + this.image(otherImage, { width: 10, height: 5, link: true }); + }; - return expect - .promise((resolve, reject) => { - const options = {}; + return expect + .promise((resolve, reject) => { + const options = {}; - if (typeof value !== 'number' && typeof value !== 'undefined') { - ['ignoreColors', 'ignoreAntialiasing'].forEach((optionName) => { - if (optionName in value) { - const ignoreValue = optionName.replace( - /^ignore(.)/, - (match, firstChar) => firstChar.toLowerCase() - ); + if (typeof value !== 'number' && typeof value !== 'undefined') { + ['ignoreColors', 'ignoreAntialiasing'].forEach((optionName) => { + if (optionName in value) { + const ignoreValue = optionName.replace( + /^ignore(.)/, + (match, firstChar) => firstChar.toLowerCase() + ); - if (Array.isArray(options.ignore)) { - options.ignore.push(ignoreValue); - } else if (options.ignore !== undefined) { - options.ignore = [options.ignore, ignoreValue]; + if (Array.isArray(options.ignore)) { + options.ignore.push(ignoreValue); + } else if (options.ignore !== undefined) { + options.ignore = [options.ignore, ignoreValue]; + } else { + options.ignore = ignoreValue; + } + delete value[optionName]; + } + }); + } + + resemble.compare( + subject, + otherImage, + options, + (err, resemblance) => { + if (err) { + reject(err); } else { - options.ignore = ignoreValue; + resolve(resemblance); } - delete value[optionName]; } - }); - } - - resemble.compare(subject, otherImage, options, (err, resemblance) => { - if (err) { - reject(err); - } else { - resolve(resemblance); + ); + }) + .then((data) => { + data.mismatchPercentage = data.misMatchPercentage; + delete data.misMatchPercentage; + if (typeof data.mismatchPercentage === 'string') { + data.mismatchPercentage = parseFloat(data.mismatchPercentage); } - }); - }) - .then((data) => { - data.mismatchPercentage = data.misMatchPercentage; - delete data.misMatchPercentage; - if (typeof data.mismatchPercentage === 'string') { - data.mismatchPercentage = parseFloat(data.mismatchPercentage); - } - // remove properties returned from newer the resemble/canvas versions - delete data.rawMisMatchPercentage; - delete data.diffBounds; + // remove properties returned from newer the resemble/canvas versions + delete data.rawMisMatchPercentage; + delete data.diffBounds; - const getImageDataUrl = data.getImageDataUrl; - // These are noisy in the 'to satisfy' diff output - delete data.analysisTime; - delete data.getBuffer; - delete data.getImageDataUrl; - delete data.pngStream; + const getImageDataUrl = data.getImageDataUrl; + // These are noisy in the 'to satisfy' diff output + delete data.analysisTime; + delete data.getBuffer; + delete data.getImageDataUrl; + delete data.pngStream; - let normalizedValue; + let normalizedValue; - if (typeof value === 'number') { - normalizedValue = { - isSameDimensions: true, - mismatchPercentage: expect.it('to be less than', value), - }; - } else if (value) { - normalizedValue = objectAssign({}, value); + if (typeof value === 'number') { + normalizedValue = { + isSameDimensions: true, + mismatchPercentage: expect.it('to be less than', value), + }; + } else if (value) { + normalizedValue = objectAssign({}, value); - if ('misMatchPercentage' in value) { - normalizedValue.mismatchPercentage = value.misMatchPercentage; - delete normalizedValue.misMatchPercentage; + if ('misMatchPercentage' in value) { + normalizedValue.mismatchPercentage = value.misMatchPercentage; + delete normalizedValue.misMatchPercentage; + } + } else { + normalizedValue = { + isSameDimensions: true, + mismatchPercentage: expect.it('to be less than', 1), + }; } - } else { - normalizedValue = { - isSameDimensions: true, - mismatchPercentage: expect.it('to be less than', 1), - }; - } - return expect.withError( - () => expect(data, 'to satisfy', normalizedValue), - (err) => { - expect.fail({ - diff(output, diff, inspect, equal) { - output - .append(err.getDiff(output.format)) - .nl(2) - .image(getImageDataUrl.call(data), { - fallbackToDisc: true, - }); + return expect.withError( + () => expect(data, 'to satisfy', normalizedValue), + (err) => { + expect.fail({ + diff(output, diff, inspect, equal) { + output + .append(err.getDiff(output.format)) + .nl(2) + .image(getImageDataUrl.call(data), { + fallbackToDisc: true, + }); - output.inline = false; - return output; - }, - }); - } - ); - }); - }); + output.inline = false; + return output; + }, + }); + } + ); + }); + } + ); }, };