-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
820 additions
and
981 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 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,21 +1,24 @@ | ||
import { expect, test } from 'vitest' | ||
import { readFileSync } from 'node:fs'; | ||
import { resolve } from 'node:path'; | ||
import { expect, test } from 'vitest'; | ||
import { PngPageOutput, pdfToPng } from '../src'; | ||
import { comparePNG } from '../src/compare.png'; | ||
|
||
test(`should convert PDF with layers`, async () => { | ||
const pdfFilePath: string = resolve('./test-data/layers/layers.pdf'); | ||
const pdfFilePath: string = resolve('./test-data/layers.pdf'); | ||
const pngPages: PngPageOutput[] = await pdfToPng(pdfFilePath, { | ||
outputFolder: 'test-results/layers/actual', | ||
}); | ||
|
||
pngPages.forEach((pngPage: PngPageOutput) => { | ||
const expectedFilePath: string = resolve('./test-data/layers/expected', pngPage.name); | ||
const actualFileContent: Buffer = readFileSync(pngPage.path); | ||
const compareResult: number = comparePNG(actualFileContent, expectedFilePath); | ||
const compareResult: number = comparePNG({ | ||
actualFile: actualFileContent, | ||
expectedFile: expectedFilePath, | ||
createExpectedFileIfMissing: true, | ||
}); | ||
|
||
expect(compareResult).to.equal(0); | ||
}); | ||
}); | ||
|
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
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,10 @@ | ||
import { resolve } from 'node:path'; | ||
import { expect, test } from 'vitest'; | ||
import { PngPageOutput, pdfToPng } from '../src'; | ||
|
||
test(`should convert BIG sample`, async () => { | ||
const pdfFilePath: string = resolve('./test-data/10-page-sample.pdf'); | ||
const pngPages: PngPageOutput[] = await pdfToPng(pdfFilePath); | ||
|
||
expect(pngPages.length).to.eq(10); | ||
}); |
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,26 @@ | ||
import { readFileSync } from 'node:fs'; | ||
import { resolve } from 'node:path'; | ||
import { expect, test } from 'vitest'; | ||
import { PngPageOutput, pdfToPng } from '../src'; | ||
import { comparePNG } from '../src/compare.png'; | ||
|
||
test(`should convert simple sample`, async () => { | ||
const pdfFilePath: string = resolve('./test-data/sample.pdf'); | ||
const pngPages: PngPageOutput[] = await pdfToPng(pdfFilePath, { | ||
outputFolder: 'test-results/sample/actual', | ||
viewportScale: 2.0, | ||
}); | ||
|
||
expect(pngPages.length).to.equal(2); | ||
pngPages.forEach((pngPage: PngPageOutput) => { | ||
const expectedFilePath: string = resolve('./test-data/sample/expected', pngPage.name); | ||
const actualFileContent: Buffer = readFileSync(pngPage.path); | ||
const compareResult: number = comparePNG({ | ||
actualFile: actualFileContent, | ||
expectedFile: expectedFilePath, | ||
createExpectedFileIfMissing: true, | ||
}); | ||
|
||
expect(compareResult).to.equal(0); | ||
}); | ||
}); |
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
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
Oops, something went wrong.