2
0
mirror of https://github.com/thumbsup/thumbsup synced 2024-11-15 18:12:46 +00:00

test: add unit test when exiftool output cannot be parsed

This commit is contained in:
Romain 2024-01-04 21:26:49 +00:00
parent 9def14a641
commit b7b33db7b0

View File

@ -36,7 +36,8 @@ describe('exiftool stream', function () {
})
// check the data returned
const stream = exifStream.parse('input', ['IMG_0001.jpg', 'IMG_0002.jpg'])
reduceStream(stream, emittedData => {
reduceStream(stream, (err, emittedData) => {
should(err).eql(null)
should(emittedData).eql([{
SourceFile: 'IMG_0001.jpg',
MIMEType: 'image/jpeg'
@ -59,20 +60,45 @@ describe('exiftool stream', function () {
})
// check the data returned
const stream = exifStream.parse('input', ['IMG_0001.jpg'])
reduceStream(stream, emittedData => {
reduceStream(stream, (err, emittedData) => {
should(err).eql(null)
should(emittedData).eql([])
debug.assertContains('installed on your system')
debug.assertContains('spawn ENOENT')
done()
})
})
it('sends an errors if exiftool response cannot be parsed', (done) => {
// setup a mock that returns invalid JSON on stdout
// this can happen if the exiftool arguments are invalid
const errorSpawn = mockSpawn()
childProcess.spawn.callsFake(errorSpawn)
errorSpawn.setDefault(function (cb) {
setTimeout(() => {
this.stdout.write('ERROR: bad syntax')
}, 10)
setTimeout(() => cb(), 20)
})
// check the data returned
const stream = exifStream.parse('input', ['IMG_0001.jpg', 'IMG_0002.jpg'])
reduceStream(stream, (err) => {
should(err).not.eql(null)
should(err).property('message').match(/Invalid JSON/)
done()
})
})
})
function reduceStream (stream, done) {
const emittedData = []
stream.on('data', entry => {
emittedData.push(entry)
}).on('end', () => {
done(emittedData)
})
stream.on('error', (err) => {
done(err, emittedData)
})
stream.on('end', () => {
done(null, emittedData)
})
}