-
Notifications
You must be signed in to change notification settings - Fork 6
/
make-pdf-thumbnail.spec.js
62 lines (53 loc) · 1.87 KB
/
make-pdf-thumbnail.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(function() {
'use strict';
var makePdfThumbnail = require('./make-pdf-thumbnail'),
fs = require('fs'),
bufferEqual = require('buffer-equal');
var inputFilename = 'test/pdf/test.pdf';
var pdfDataStream = fs.createReadStream(inputFilename);
var pdfBuffer = fs.readFileSync(inputFilename);
describe('make-pdf-thumbnail', function() {
var result;
it('thumbnail from stream', function(done){
result = {};
makePdfThumbnail.fromStream(pdfDataStream, 72, function(err, outputStream) {
expect(err).toBeFalsy();
var buffers = [];
outputStream.on('data', function(pieceBuffer) {
buffers.push(pieceBuffer);
});
outputStream.on('end', function() {
expect(Buffer.concat(buffers).length > 0).toBe(true);
done();
});
outputStream.on('error', function (streamErr){
expect(streamErr).toBeFalse();
done();
});
});
});
it('thumbnail from buffer', function(done) {
makePdfThumbnail.fromBuffer(pdfBuffer, 72, function(err, buffer) {
expect(err).toBeFalsy();
expect(buffer.length).toBeGreaterThan(0);
done();
});
});
it('thumbnail from file', function(done) {
makePdfThumbnail.fromFile(inputFilename, 'test-output/output.png', 72, function(err) {
var outputBuffer = fs.readFileSync('test-output/output.png');
expect(outputBuffer.length).toBeGreaterThan(0);
expect(err).toBeFalsy();
done();
});
});
it('thumbnail from stream to file', function(done) {
makePdfThumbnail.fromStreamToFile(pdfDataStream, 'test-output/output.png', 72, function(err) {
var outputBuffer = fs.readFileSync('test-output/output.png');
expect(err).toBeFalsy();
expect(outputBuffer.length).toBeGreaterThan(0);
done();
});
});
});
})();