test: check actual output generated from printToPDF (#21949)
This commit is contained in:
parent
1f61b3a3eb
commit
23382e6e08
5 changed files with 1432 additions and 1 deletions
|
@ -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++) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue