-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
24b3d27
commit 23f9c87
Showing
24 changed files
with
1,878 additions
and
751 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
build | ||
tests | ||
integration-output |
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,34 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: ['**'] | ||
|
||
jobs: | ||
test: | ||
name: Node v${{ matrix.node-version }} on ${{ matrix.os }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest] | ||
node-version: [18.x] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- run: sudo apt-get update | ||
- run: sudo apt-get install ghostscript | ||
- run: sudo apt-get install graphicsmagick | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
os: ${{ matrix.os }} | ||
cache: 'npm' | ||
- name: Install packages for project | ||
run: npm ci | ||
- name: Run tests | ||
run: | | ||
npm run test |
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 |
---|---|---|
|
@@ -14,4 +14,7 @@ coverage | |
.DS_Store | ||
|
||
# integration | ||
integration-output | ||
integration-output | ||
|
||
# tests | ||
__tests__/stubs |
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,2 +1,2 @@ | ||
registry=https://registry.npmjs.org | ||
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = true | ||
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = true |
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
# Build | ||
build | ||
integration-output | ||
|
||
#node | ||
node_modules |
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
Binary file added
BIN
+8.63 KB
__tests__/__image_snapshots__/index-test-ts-integration-works-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.76 KB
__tests__/__image_snapshots__/index-test-ts-integration-works-2-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.4 KB
__tests__/__image_snapshots__/index-test-ts-integration-works-3-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+42.4 KB
__tests__/__image_snapshots__/index-test-ts-integration-works-4-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+237 KB
__tests__/__image_snapshots__/index-test-ts-integration-works-5-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15 KB
__tests__/__image_snapshots__/index-test-ts-integration-works-6-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+75.1 KB
__tests__/__image_snapshots__/index-test-ts-integration-works-7-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,55 @@ | ||
import {dirname, join, resolve} from 'path'; | ||
|
||
import {toMatchImageSnapshot} from 'jest-image-snapshot'; | ||
import {fromPath} from 'pdf2pic'; | ||
import puppeteer from 'puppeteer'; | ||
import {Browser} from 'puppeteer-core'; | ||
|
||
import {generatePdf} from '../src'; | ||
|
||
expect.extend({toMatchImageSnapshot}); | ||
|
||
describe('integration', () => { | ||
let browser: Browser; | ||
|
||
const pdfFile = resolve(__dirname, '../integration-output/en/single-page.pdf'); | ||
const options = { | ||
density: 100, | ||
format: 'png', | ||
width: 794, | ||
height: 1123, | ||
}; | ||
const convertPdf2Pic = fromPath(pdfFile, options); | ||
const numberOfPages = 7; | ||
|
||
beforeAll(async () => { | ||
// @ts-ignore | ||
browser = await puppeteer.launch({headless: true}); | ||
|
||
await generatePdf({ | ||
singlePagePath: join(dirname(pdfFile), 'single-page.json'), | ||
browser, | ||
}); | ||
}); | ||
|
||
it('works', async () => { | ||
for (let currentPage = 1; currentPage <= numberOfPages; currentPage++) { | ||
const {buffer: expectedImage} = await convertPdf2Pic(currentPage, { | ||
responseType: 'buffer', | ||
}); | ||
|
||
expect(expectedImage).toMatchImageSnapshot({ | ||
failureThreshold: 0.1, | ||
failureThresholdType: 'percent', | ||
}); | ||
} | ||
}); | ||
|
||
afterAll(async () => { | ||
if (!browser) { | ||
return; | ||
} | ||
|
||
await browser.close(); | ||
}); | ||
}); |
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,6 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testMatch: ['**/?(*.)+(test).[tj]s?(x)'], | ||
testTimeout: 1000000, | ||
}; |
Oops, something went wrong.