getDocument hangs in Jest/JSDom environment
See original GitHub issueOn PDF.js 2.0.385 and later, running the following simplest example:
pdf.getDocument({ data: arrayBufferData })
.then(() => console.log('Success'))
.catch() => console.log('Fail'));
runs fine on Node.js, obviously.
Running the same piece in Jest, as in this example (simplified, please ignore the fact the tests should be async):
describe('Test', () => {
it('does something', () => {
pdf.getDocument({ data: arrayBufferData })
.then(() => console.log('Success'))
.catch() => console.log('Fail'));
});
}
- if
testEnvironment
is set to"node"
, succeeds. - if
testEnvironment
is set to"jsdom"
(default), hangs and never reaches.then()
.
On PDF.js 2.0.305 and earlier this is not an issue, because you can easily disable workers manually.
Now that there’s no way of doing that via config as of #9385, all projects using PDF.js and Jest/JSDom will be unable to test anything PDF.js-related. Switching testEnvironment
to "node"
is usually not an option as this will cause virtually everything else on front-end to fail.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
JavaScript - can't get jsdom document in Jest test
I have a module that provides some convenience functions for DOM manipulation that I'm trying to test with Jest and ...
Read more >Troubleshooting - Jest
Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why. Try using the debugging support built into...
Read more >Why Jest freezes after tests run? (Jest hangs indefinitely)
If you noticed that Jest (npm / yarn) test hang at the end of the test execution while you run tests in parallel...
Read more >Use Jest write unit testing for DOM manipulation
so we must ready DOM for test case of addTodo ! As mention document of Jest: Jest ships with jsdom which simulates a...
Read more >Changelog.md - jest-environment-jsdom-fourteen - GitLab
Fixed HTML serialization (e.g. via innerHTML ) breaking after setting certain properties to non-string values. Fixed how disabling an element ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve managed to deal with it! For those stuck like me, do NOT set
pdfjs.GlobalWorkerOptions.workerSrc
orpdfjs.GlobalWorkerOptions.workerPort
. Instead, use pdf.worker.entry.js file - simply import it and you’re done!The above solution didn’t work for me, instead I had to configure jest to use node instead of jsdom (enabled by default)
Adding this to the top of my spec file solved it