test: check actual output generated from printToPDF (#21949)

This commit is contained in:
Shelley Vohr 2020-01-30 20:12:35 +00:00 committed by GitHub
parent 1f61b3a3eb
commit 23382e6e08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 1432 additions and 1 deletions

View file

@ -9,6 +9,7 @@ import { emittedOnce } from './events-helpers'
import { closeAllWindows } from './window-helpers'
import { ifdescribe, ifit } from './spec-helpers'
const pdfjs = require('pdfjs-dist')
const fixturesPath = path.resolve(__dirname, '..', 'spec', 'fixtures')
const features = process.electronBinding('features')
@ -1447,6 +1448,29 @@ describe('webContents module', () => {
expect(data).to.be.an.instanceof(Buffer).that.is.not.empty()
})
it('respects custom settings', async () => {
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'print-to-pdf.html'))
await emittedOnce(w.webContents, 'did-finish-load')
const data = await w.webContents.printToPDF({
pageRanges: {
from: 0,
to: 2
},
landscape: true
})
const doc = await pdfjs.getDocument(data).promise
// Check that correct # of pages are rendered.
expect(doc.numPages).to.equal(3)
// Check that PDF is generated in landscape mode.
const firstPage = await doc.getPage(1)
const { width, height } = firstPage.getViewport({ scale: 100 })
expect(width).to.be.greaterThan(height)
})
it('does not crash when called multiple times', async () => {
const promises = []
for (let i = 0; i < 2; i++) {