faint-ocean-92094
02/20/2023, 10:46 PMconst pdf = require('pdf-parse');
getPdfContent(pdfName) {
return pdf(fs.readFileSync('cypress/downloads/' + pdfName))
}
On my test I call
cy.task("getPdfContent", "Test PDF File.pdf").then(content => {
expect(content.text).to.have.string("Testing content")
})
Sometimes the test passes like a charm, but sometimes I get the error bad XRef Entry. For what I have read this is a problem with the PDF file but the PDF file I download is fine. Furthermore if I rerun the same process with the same file, it works fine.
So it looks like the problem is what readFileSync is passing to the pdf() function. My theory is that the process is not finished when pdf() wants to parse it, as it only happens sometimes.
But I can't figure out what is going on. Could it be that readFileSync is not working correctly everytime?
Is there a way to verify or wait for it to finish before calling pdf() on it?faint-ocean-92094
02/20/2023, 11:05 PMnutritious-honey-65632
02/20/2023, 11:10 PMfaint-ocean-92094
02/20/2023, 11:16 PMfaint-ocean-92094
02/20/2023, 11:16 PM