UNPKG

pdf-page-counter

Version:

Pure javascript cross-platform module to extract page count from PDFs, based on pdf-parser.

63 lines (53 loc) 1.81 kB
const assert = require('assert'); const PDF = require('../'); const fs = require('fs'); const PDF_FILE = './test/data/03-invalid.pdf'; const VERSION = 'default'; const PDF_PAGE_COUNT = 5; describe(`File:${PDF_FILE} PDF.js Version:${VERSION} ps: should all throw error.`, function() { this.timeout(20000); let dataBuffer = fs.readFileSync(PDF_FILE); it('should pass parse', function() { let options = { version: VERSION }; return PDF(dataBuffer, options).then(function(data) { assert.err("should throw error."); }) .catch(function(err) { assert.notEqual(err, null); assert.notEqual(err, undefined); }); }); it('should pass parse with option max:-1', function() { let options = { version: VERSION, max: -1 }; return PDF(dataBuffer, options).then(function(data) { assert.err("should throw error."); }).catch(function(err) { assert.notEqual(err, null); assert.notEqual(err, undefined); }); }); it(`should pass parse with option max:${PDF_PAGE_COUNT-1}`, function() { let options_01 = { version: VERSION, max: PDF_PAGE_COUNT - 1 }; let options_02 = { version: VERSION }; return PDF(dataBuffer, options_01).then(function(data) { assert.err("should throw error."); }).then(function() { return PDF(dataBuffer, options_02).then(function(data) { assert.err("should throw error."); }); }).catch(function(err) { assert.notEqual(err, null); assert.notEqual(err, undefined); }); }); });