Skip to content

Commit

Permalink
Increase detail in test output fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiasw committed Oct 31, 2021
1 parent 96365a0 commit 427d45d
Show file tree
Hide file tree
Showing 24 changed files with 77 additions and 31 deletions.
2 changes: 1 addition & 1 deletion dist/exif-reader.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/nodejs/exif.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function listTags(tags) {
} else if (Array.isArray(tags[group][name])) {
console.log(`${group}:${name}: ${tags[group][name].map((item) => item.description).join(', ')}`);
} else {
console.log(`${group}:${name}: ${tags[group][name].description}`);
console.log(`${group}:${name}: ${typeof tags[group][name].description === 'string' ? tags[group][name].description.trim() : tags[group][name].description}`);
}
}
}
Expand Down
21 changes: 14 additions & 7 deletions test/build/exif.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,20 @@ function hash(value) {
return crypto.createHash('sha1').update(new Uint8Array(value)).digest('base64');
}
value = (new Uint8Array(value)).map((byte) => Number(byte));
}
const stringified = JSON.stringify(value);
if (stringified.length > 200) {
return crypto.createHash('sha1').update(stringified).digest('base64');
}
if (Array.isArray(value)) {
return value.join(', ');
} else if (Array.isArray(value)) {
const newValue = value.length > 200 ? value.slice(0, 100).concat(['...']).concat(value.slice(-100)) : value;
return newValue.map(hash);
} else if (typeof value === 'object') {
const newValue = {};
for (const key in value) {
newValue[key] = hash(value[key]);
}
return newValue;
} else if (typeof value === 'string') {
if (value.length > 200) {
return `${value.substring(0, 100)}[...]${value.substring(value.length - 100)}`;
}
return value;
}
return value;
}
43 changes: 41 additions & 2 deletions test/build/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('image outputs', () => {

fs.readdirSync(path.join(FIXTURES_PATH, 'images')).forEach((imageName) => {
if (!filter || (path.resolve(path.join(FIXTURES_PATH, 'images', imageName)) === filter)) {
it(`matches stored image output for "${imageName}"`, () => {
describe(imageName, () => {
const storedResult = JSON.parse(fs.readFileSync(path.join(FIXTURES_PATH, 'outputs', `${imageName}.out`)));
// The process needs to be the same as when the stored result was
// created and now retrieved, i.e. first stringified and then parsed,
Expand All @@ -19,7 +19,34 @@ describe('image outputs', () => {
Exif.parse(path.join(FIXTURES_PATH, 'images', imageName))
));

expect(result).to.deep.equal(storedResult);
// deep.equal can't handle too large objects so we have to split them up.
describe('combined', () => {
if (result.combined) {
checkTags(result.combined, storedResult.combined);
} else {
it('matches', () => {
expect(result.combined).to.equal(storedResult.combined);
});
}
});

describe('expanded', () => {
if (result.expanded) {
it('matches in number of groups', () => {
expect(Object.keys(result.expanded)).to.have.lengthOf(Object.keys(storedResult.expanded).length);
});

for (const group in result.expanded) {
describe(`group "${group}"`, () => {
checkTags(result.expanded[group], storedResult.expanded[group]);
});
}
} else {
it('matches', () => {
expect(result.expanded).to.equal(storedResult.expanded);
});
}
});
});
}
});
Expand All @@ -29,4 +56,16 @@ describe('image outputs', () => {
.filter((arg) => arg.startsWith('--image='))
.map((arg) => path.resolve(arg.replace(/^--image=/, '')))[0];
}

function checkTags(tags, storedTags) {
it('matches in number of tags', () => {
expect(Object.keys(tags)).to.have.lengthOf(Object.keys(storedTags).length);
});

for (const tagName in tags) {
it(`matches for tag "${tagName}"`, () => {
expect(tags[tagName]).to.deep.equal(storedTags[tagName]);
});
}
}
});
2 changes: 1 addition & 1 deletion test/fixtures/outputs/test-iptc.jpg.out
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"combined":{"Bits Per Sample":{"value":8,"description":"8"},"Image Height":{"value":12,"description":"12px"},"Image Width":{"value":22,"description":"22px"},"Color Components":{"value":3,"description":"3"},"Subsampling":{"value":"1,17,0, 2,17,1, 3,17,1","description":"YCbCr4:4:4 (1 1)"},"Thumbnail":{"Compression":{"id":259,"value":6,"description":6},"XResolution":{"id":282,"value":[72,1],"description":"72"},"YResolution":{"id":283,"value":[72,1],"description":"72"},"ResolutionUnit":{"id":296,"value":2,"description":"inches"},"JPEGInterchangeFormat":{"id":513,"value":274,"description":274},"JPEGInterchangeFormatLength":{"id":514,"value":1212,"description":1212},"type":"image/jpeg","image":"zTp1QOOrSl/MHvIKf5mGeydWL9M=","base64":"elRwMVFPT3JTbC9NSHZJS2Y1bUdleWRXTDlNPQ=="},"XResolution":{"id":282,"value":"72, 1","description":"72"},"YResolution":{"id":283,"value":"72, 1","description":"72"},"ResolutionUnit":{"id":296,"value":2,"description":"inches"},"YCbCrPositioning":{"id":531,"value":1,"description":"centered"},"Exif IFD Pointer":{"id":34665,"value":90,"description":90},"ExifVersion":{"id":36864,"value":"48, 50, 51, 50","description":"0232"},"ComponentsConfiguration":{"id":37121,"value":"1, 2, 3, 0","description":""},"FlashpixVersion":{"id":40960,"value":"48, 49, 48, 48","description":"0100"},"ColorSpace":{"id":40961,"value":65535,"description":"Uncalibrated"},"LensModel":{"id":42036,"value":"EF24-105mm f/4L IS USM","description":"EF24-105mm f/4L IS USM"},"Sub-location":{"id":604,"value":"77, 121, 32, 83, 117, 98, 108, 111, 99, 97, 116, 105, 111, 110","description":"My Sublocation"},"Record Version":{"id":512,"value":"0, 4","description":"4"},"about":{"value":"","attributes":{},"description":""},"AuthorsPosition":{"value":"Photographer","attributes":{},"description":"Photographer"},"Preferred CMM type":{"value":"Lino","description":"Lino"},"Profile Version":{"value":"2.1.0","description":"2.1.0"},"Profile/Device class":{"value":"mntr","description":"Display Device profile"},"Color Space":{"value":"RGB ","description":"RGB "},"Connection Space":{"value":"XYZ ","description":"XYZ "},"ICC Profile Date":{"value":"1998-02-09T06:49:00.000Z","description":"1998-02-09T06:49:00.000Z"},"ICC Signature":{"value":"acsp","description":"acsp"},"Primary Platform":{"value":"MSFT","description":"Microsoft"},"Device Manufacturer":{"value":"IEC ","description":"IEC "},"Device Model Number":{"value":"sRGB","description":"sRGB"},"Rendering Intent":{"value":0,"description":"Perceptual"},"Profile Creator":{"value":"HP ","description":"HP "},"ICC Copyright":{"value":"Copyright (c) 1998 Hewlett-Packard C","description":"Copyright (c) 1998 Hewlett-Packard C"},"ICC Description":{"value":"sRGB IEC61966-2.1","description":"sRGB IEC61966-2.1"},"ICC Device Manufacturer for Display":{"value":"IEC http://www.iec.ch","description":"IEC http://www.iec.ch"},"ICC Device Model Description":{"value":"IEC 61966-2.1 Default RGB colour space - sRGB","description":"IEC 61966-2.1 Default RGB colour space - sRGB"},"ICC Viewing Conditions Description":{"value":"Reference Viewing Condition in IEC61966-2.1","description":"Reference Viewing Condition in IEC61966-2.1"},"Technology":{"value":"CRT ","description":"CRT "}},"expanded":{"file":{"Bits Per Sample":{"value":8,"description":"8"},"Image Height":{"value":12,"description":"12px"},"Image Width":{"value":22,"description":"22px"},"Color Components":{"value":3,"description":"3"},"Subsampling":{"value":"1,17,0, 2,17,1, 3,17,1","description":"YCbCr4:4:4 (1 1)"}},"Thumbnail":{"Compression":{"id":259,"value":6,"description":6},"XResolution":{"id":282,"value":[72,1],"description":"72"},"YResolution":{"id":283,"value":[72,1],"description":"72"},"ResolutionUnit":{"id":296,"value":2,"description":"inches"},"JPEGInterchangeFormat":{"id":513,"value":274,"description":274},"JPEGInterchangeFormatLength":{"id":514,"value":1212,"description":1212},"type":"image/jpeg","image":"zTp1QOOrSl/MHvIKf5mGeydWL9M=","base64":"elRwMVFPT3JTbC9NSHZJS2Y1bUdleWRXTDlNPQ=="},"exif":{"XResolution":{"id":282,"value":"72, 1","description":"72"},"YResolution":{"id":283,"value":"72, 1","description":"72"},"ResolutionUnit":{"id":296,"value":2,"description":"inches"},"YCbCrPositioning":{"id":531,"value":1,"description":"centered"},"Exif IFD Pointer":{"id":34665,"value":90,"description":90},"ExifVersion":{"id":36864,"value":"48, 50, 51, 50","description":"0232"},"ComponentsConfiguration":{"id":37121,"value":"1, 2, 3, 0","description":""},"FlashpixVersion":{"id":40960,"value":"48, 49, 48, 48","description":"0100"},"ColorSpace":{"id":40961,"value":65535,"description":"Uncalibrated"},"LensModel":{"id":42036,"value":"EF24-105mm f/4L IS USM","description":"EF24-105mm f/4L IS USM"}},"iptc":{"Sub-location":{"id":604,"value":"77, 121, 32, 83, 117, 98, 108, 111, 99, 97, 116, 105, 111, 110","description":"My Sublocation"},"Record Version":{"id":512,"value":"0, 4","description":"4"}},"xmp":{"about":{"value":"","attributes":{},"description":""},"AuthorsPosition":{"value":"Photographer","attributes":{},"description":"Photographer"}},"icc":{"Preferred CMM type":{"value":"Lino","description":"Lino"},"Profile Version":{"value":"2.1.0","description":"2.1.0"},"Profile/Device class":{"value":"mntr","description":"Display Device profile"},"Color Space":{"value":"RGB ","description":"RGB "},"Connection Space":{"value":"XYZ ","description":"XYZ "},"ICC Profile Date":{"value":"1998-02-09T06:49:00.000Z","description":"1998-02-09T06:49:00.000Z"},"ICC Signature":{"value":"acsp","description":"acsp"},"Primary Platform":{"value":"MSFT","description":"Microsoft"},"Device Manufacturer":{"value":"IEC ","description":"IEC "},"Device Model Number":{"value":"sRGB","description":"sRGB"},"Rendering Intent":{"value":0,"description":"Perceptual"},"Profile Creator":{"value":"HP ","description":"HP "},"ICC Copyright":{"value":"Copyright (c) 1998 Hewlett-Packard C","description":"Copyright (c) 1998 Hewlett-Packard C"},"ICC Description":{"value":"sRGB IEC61966-2.1","description":"sRGB IEC61966-2.1"},"ICC Device Manufacturer for Display":{"value":"IEC http://www.iec.ch","description":"IEC http://www.iec.ch"},"ICC Device Model Description":{"value":"IEC 61966-2.1 Default RGB colour space - sRGB","description":"IEC 61966-2.1 Default RGB colour space - sRGB"},"ICC Viewing Conditions Description":{"value":"Reference Viewing Condition in IEC61966-2.1","description":"Reference Viewing Condition in IEC61966-2.1"},"Technology":{"value":"CRT ","description":"CRT "}}}}
{"combined":{"Bits Per Sample":{"value":8,"description":"8"},"Image Height":{"value":12,"description":"12px"},"Image Width":{"value":22,"description":"22px"},"Color Components":{"value":3,"description":"3"},"Subsampling":{"value":[[1,17,0],[2,17,1],[3,17,1]],"description":"YCbCr4:4:4 (1 1)"},"Thumbnail":{"Compression":{"id":259,"value":6,"description":6},"XResolution":{"id":282,"value":[72,1],"description":"72"},"YResolution":{"id":283,"value":[72,1],"description":"72"},"ResolutionUnit":{"id":296,"value":2,"description":"inches"},"JPEGInterchangeFormat":{"id":513,"value":274,"description":274},"JPEGInterchangeFormatLength":{"id":514,"value":1212,"description":1212},"type":"image/jpeg","image":"zTp1QOOrSl/MHvIKf5mGeydWL9M=","base64":"elRwMVFPT3JTbC9NSHZJS2Y1bUdleWRXTDlNPQ=="},"XResolution":{"id":282,"value":[72,1],"description":"72"},"YResolution":{"id":283,"value":[72,1],"description":"72"},"ResolutionUnit":{"id":296,"value":2,"description":"inches"},"YCbCrPositioning":{"id":531,"value":1,"description":"centered"},"Exif IFD Pointer":{"id":34665,"value":90,"description":90},"ExifVersion":{"id":36864,"value":[48,50,51,50],"description":"0232"},"ComponentsConfiguration":{"id":37121,"value":[1,2,3,0],"description":""},"FlashpixVersion":{"id":40960,"value":[48,49,48,48],"description":"0100"},"ColorSpace":{"id":40961,"value":65535,"description":"Uncalibrated"},"LensModel":{"id":42036,"value":["EF24-105mm f/4L IS USM"],"description":"EF24-105mm f/4L IS USM"},"Sub-location":{"id":604,"value":[77,121,32,83,117,98,108,111,99,97,116,105,111,110],"description":"My Sublocation"},"Record Version":{"id":512,"value":[0,4],"description":"4"},"about":{"value":"","attributes":{},"description":""},"AuthorsPosition":{"value":"Photographer","attributes":{},"description":"Photographer"},"Preferred CMM type":{"value":"Lino","description":"Lino"},"Profile Version":{"value":"2.1.0","description":"2.1.0"},"Profile/Device class":{"value":"mntr","description":"Display Device profile"},"Color Space":{"value":"RGB ","description":"RGB "},"Connection Space":{"value":"XYZ ","description":"XYZ "},"ICC Profile Date":{"value":"1998-02-09T06:49:00.000Z","description":"1998-02-09T06:49:00.000Z"},"ICC Signature":{"value":"acsp","description":"acsp"},"Primary Platform":{"value":"MSFT","description":"Microsoft"},"Device Manufacturer":{"value":"IEC ","description":"IEC "},"Device Model Number":{"value":"sRGB","description":"sRGB"},"Rendering Intent":{"value":0,"description":"Perceptual"},"Profile Creator":{"value":"HP ","description":"HP "},"ICC Copyright":{"value":"Copyright (c) 1998 Hewlett-Packard C","description":"Copyright (c) 1998 Hewlett-Packard C"},"ICC Description":{"value":"sRGB IEC61966-2.1","description":"sRGB IEC61966-2.1"},"ICC Device Manufacturer for Display":{"value":"IEC http://www.iec.ch","description":"IEC http://www.iec.ch"},"ICC Device Model Description":{"value":"IEC 61966-2.1 Default RGB colour space - sRGB","description":"IEC 61966-2.1 Default RGB colour space - sRGB"},"ICC Viewing Conditions Description":{"value":"Reference Viewing Condition in IEC61966-2.1","description":"Reference Viewing Condition in IEC61966-2.1"},"Technology":{"value":"CRT ","description":"CRT "}},"expanded":{"file":{"Bits Per Sample":{"value":8,"description":"8"},"Image Height":{"value":12,"description":"12px"},"Image Width":{"value":22,"description":"22px"},"Color Components":{"value":3,"description":"3"},"Subsampling":{"value":[[1,17,0],[2,17,1],[3,17,1]],"description":"YCbCr4:4:4 (1 1)"}},"Thumbnail":{"Compression":{"id":259,"value":6,"description":6},"XResolution":{"id":282,"value":[72,1],"description":"72"},"YResolution":{"id":283,"value":[72,1],"description":"72"},"ResolutionUnit":{"id":296,"value":2,"description":"inches"},"JPEGInterchangeFormat":{"id":513,"value":274,"description":274},"JPEGInterchangeFormatLength":{"id":514,"value":1212,"description":1212},"type":"image/jpeg","image":"zTp1QOOrSl/MHvIKf5mGeydWL9M=","base64":"elRwMVFPT3JTbC9NSHZJS2Y1bUdleWRXTDlNPQ=="},"exif":{"XResolution":{"id":282,"value":[72,1],"description":"72"},"YResolution":{"id":283,"value":[72,1],"description":"72"},"ResolutionUnit":{"id":296,"value":2,"description":"inches"},"YCbCrPositioning":{"id":531,"value":1,"description":"centered"},"Exif IFD Pointer":{"id":34665,"value":90,"description":90},"ExifVersion":{"id":36864,"value":[48,50,51,50],"description":"0232"},"ComponentsConfiguration":{"id":37121,"value":[1,2,3,0],"description":""},"FlashpixVersion":{"id":40960,"value":[48,49,48,48],"description":"0100"},"ColorSpace":{"id":40961,"value":65535,"description":"Uncalibrated"},"LensModel":{"id":42036,"value":["EF24-105mm f/4L IS USM"],"description":"EF24-105mm f/4L IS USM"}},"iptc":{"Sub-location":{"id":604,"value":[77,121,32,83,117,98,108,111,99,97,116,105,111,110],"description":"My Sublocation"},"Record Version":{"id":512,"value":[0,4],"description":"4"}},"xmp":{"about":{"value":"","attributes":{},"description":""},"AuthorsPosition":{"value":"Photographer","attributes":{},"description":"Photographer"}},"icc":{"Preferred CMM type":{"value":"Lino","description":"Lino"},"Profile Version":{"value":"2.1.0","description":"2.1.0"},"Profile/Device class":{"value":"mntr","description":"Display Device profile"},"Color Space":{"value":"RGB ","description":"RGB "},"Connection Space":{"value":"XYZ ","description":"XYZ "},"ICC Profile Date":{"value":"1998-02-09T06:49:00.000Z","description":"1998-02-09T06:49:00.000Z"},"ICC Signature":{"value":"acsp","description":"acsp"},"Primary Platform":{"value":"MSFT","description":"Microsoft"},"Device Manufacturer":{"value":"IEC ","description":"IEC "},"Device Model Number":{"value":"sRGB","description":"sRGB"},"Rendering Intent":{"value":0,"description":"Perceptual"},"Profile Creator":{"value":"HP ","description":"HP "},"ICC Copyright":{"value":"Copyright (c) 1998 Hewlett-Packard C","description":"Copyright (c) 1998 Hewlett-Packard C"},"ICC Description":{"value":"sRGB IEC61966-2.1","description":"sRGB IEC61966-2.1"},"ICC Device Manufacturer for Display":{"value":"IEC http://www.iec.ch","description":"IEC http://www.iec.ch"},"ICC Device Model Description":{"value":"IEC 61966-2.1 Default RGB colour space - sRGB","description":"IEC 61966-2.1 Default RGB colour space - sRGB"},"ICC Viewing Conditions Description":{"value":"Reference Viewing Condition in IEC61966-2.1","description":"Reference Viewing Condition in IEC61966-2.1"},"Technology":{"value":"CRT ","description":"CRT "}}}}
Loading

0 comments on commit 427d45d

Please sign in to comment.