generated from victorsoares96/lib-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from victorsoares96/test/add-tests
test/add tests
- Loading branch information
Showing
10 changed files
with
77 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import compress from '../src/compress'; | ||
import * as testHelper from './test.helper'; | ||
|
||
describe('compress', () => { | ||
it('should compress a pdf file', async () => { | ||
const originalFilePath = path.resolve( | ||
__dirname, | ||
'../examples/A17_FlightPlan.pdf' | ||
); | ||
|
||
const originalFile = await fs.promises.readFile(originalFilePath); | ||
const originalPDF = await testHelper.parsePDF(originalFilePath); | ||
|
||
const compressedFile = await compress(originalFilePath); | ||
const compressedPDF = await testHelper.parsePDF(compressedFile); | ||
|
||
expect(compressedFile.length).toBeLessThan(originalFile.length); | ||
expect(compressedPDF.numpages).toEqual(originalPDF.numpages); | ||
expect(compressedPDF.numrender).toEqual(originalPDF.numrender); | ||
expect(compressedPDF.text).toEqual(originalPDF.text); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import fs from 'fs'; | ||
import type pdfParser from 'pdf-parse'; | ||
|
||
// https://gitlab.com/autokent/pdf-parse/-/issues/24 | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const PDFParser = require('pdf-parse'); | ||
|
||
export async function parsePDF( | ||
file: string | Buffer, | ||
options?: pdfParser.Options | ||
): Promise<pdfParser.Result> { | ||
let dataBuffer: Buffer; | ||
|
||
if (typeof file === 'string') { | ||
dataBuffer = fs.readFileSync(file); | ||
} else dataBuffer = file; | ||
|
||
const data = await PDFParser(dataBuffer, options); | ||
|
||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export { default as getGSModulePath } from './get-gs-module-path'; | ||
export { default as getBinPath } from './get-bin-path'; | ||
export { default as compress } from './compress'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters