| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 | var expect = require('chai').expect;var fs = require('fs');var QrCode = require('../dist/index.js');var ImageParser = require("image-parser");const Jimp = require("jimp");const expectedResult = {  "result": 'Test',  "points": [    {      "count": 2,      "estimatedModuleSize": 8,      "x": 36,      "y": 148,    },    {      "count": 2,      "estimatedModuleSize": 8,      "x": 36,      "y": 36,    },    {      "count": 2,      "estimatedModuleSize": 8,      "x": 148,      "y": 36,    }  ]};function copy(input) {  return JSON.parse(JSON.stringify(input));}it("should work with jimp", function(done) {  var buffer = fs.readFileSync(__dirname + '/image.png');  Jimp.read(buffer, function(err, image) {    if (err) {      return done(err);    }    var qr = new QrCode();    qr.callback = function(err, result) {      if (err) {        return done(err);      }      expect(copy(result)).to.deep.equal(expectedResult);      done();    };    qr.decode(image.bitmap);  });});it("should work with a zxing qr code with jimp", function(done) {  var buffer = fs.readFileSync(__dirname + '/image-zxing.png');  Jimp.read(buffer, function(err, image) {    if (err) {      return done(err);    }    var qr = new QrCode();    qr.callback = function(err, result) {      if (err) {        return done(err);      }      expect(copy(result)).to.deep.equal({        "result": 'Test',        "points": [          {            "count": 2,            "estimatedModuleSize": 9,            "x": 34.5,            "y": 160.5,          },          {            "count": 3,            "estimatedModuleSize": 9,            "x": 34.5,            "y": 34.5,          },          {            "count": 2,            "estimatedModuleSize": 9.428571428571429,            "x": 160.5,            "y": 34.5,          }        ]      });      done();    };    qr.decode(image.bitmap);  });});it('should work with basic image', function(done) {  var buffer = fs.readFileSync(__dirname + '/image.png');  var img = new ImageParser(buffer);  img.parse(function(err) {    if (err) {      return done(err);    }    var qr = new QrCode();    qr.callback = function(err, result) {      if (err) {        return done(err);      }      expect(copy(result)).to.deep.equal(expectedResult);      done();    };    qr.decode({width: img.width(), height: img.height()}, img._imgBuffer);  });});it('should work with imageData format', function(done) {  var buffer = fs.readFileSync(__dirname + '/image.png');  var img = new ImageParser(buffer);  img.parse(function(err) {    if (err) {      return done(err);    }    var qr = new QrCode();    qr.callback = function(err, result) {      if (err) {        return done(err);      }      expect(copy(result)).to.deep.equal({        "result": 'Test',        "points": [          {            "count": 2,            "estimatedModuleSize": 8,            "x": 36,            "y": 148,          },          {            "count": 2,            "estimatedModuleSize": 8,            "x": 36,            "y": 36,          },          {            "count": 2,            "estimatedModuleSize": 8,            "x": 148,            "y": 36,          }        ]      });      done();    };    qr.decode({height: img.height(), width: img.width(), data: img._imgBuffer});  });});
 |