Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

librsvg

Package Overview
Dependencies
Maintainers
4
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

librsvg - npm Package Compare versions

Comparing version 0.6.2 to 0.6.3

test/helpers/generate-reference-images.js

2

package.json
{
"name": "librsvg",
"version": "0.6.2",
"version": "0.6.3",
"description": "Parse SVG files and render them as PNG, PDF, SVG, or raw memory buffer images.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -6,2 +6,4 @@ 'use strict';

var Rsvg = require('..').Rsvg;
var fs = require('fs');
var path = require('path');

@@ -233,2 +235,55 @@ describe('Rsvg', function() {

describe('reference rendering', function () {
var items = fs.readdirSync('./test/svg/');
// sinon.assert.pass = function (message) { console.log(message); };
items.forEach(function (testcase) {
if (testcase.slice(-4) === '.svg') {
it('png image should match the reference image "' + testcase + '"', function () {
var fn = testcase.slice(0, -4);
var input = fs.readFileSync('./test/svg/' + fn + '.svg');
var svg = new Rsvg(input);
var rendering = new Buffer(svg.render({
format: 'png',
width: svg.width,
height: svg.height
}).data);
var compare = function (rendering, referenceFn) {
var reference = fs.readFileSync('./test/png/' + referenceFn + '.png');
try{
return Buffer.compare(reference, rendering);
} catch (e){
// TODO: Remove workaround after support for node 0.10 was dropped
if ( JSON.stringify(reference) === JSON.stringify(rendering) ) {
return 0;
} else {
return -1;
}
}
};
if( compare(rendering, fn) === 0 ){
return;
} else {
var i = 1;
while (fs.existsSync('./test/png/' + fn + '-variant' + i + '.png')){
if ( compare(rendering, fn + '-variant' + i ) === 0){
sinon.assert.pass(fn + ' passed using variant ' + i);
return;
}
i++;
}
}
var base64 = 'data:image/png;base64,' + rendering.toString('base64');
sinon.assert.fail('Image does not match reference!\n' +
'To view the image convert the base64 encoded string to an actual image.\n' +
'You can use a online decoder like' +
' http://www.askapache.com/online-tools/base64-image-converter\n' +
'un-check "Compress Image (png and jpeg)" to get a result that can be used as reference.\n' +
'If you think the rendering result looks good save it as\n' +
path.resolve('./test/png') + '/' + fn + '-variant' + i + '.png\n'+ base64);
});
}
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc