dferber90 / jsdom-screenshot

📸 Take screenshots of jsdom with puppeteer
https://github.com/dferber90/visual-regression-testing-example
MIT License
65 stars 18 forks source link

takeScreenshot hangs on missing assets #18

Open good-idea opened 3 years ago

good-idea commented 3 years ago

I was having an issue where my test suddenly started timing out -- I finally debugged it by launching chromium with generateImage({ launch: { ... } }). I noticed in the network tab that the request for a font file was pending, and would never resolve (either with the resource or as a 404).

This was solved by adding my asset directory to the options (serve: ['public']). But, it was quite difficult to figure out that this was the issue. Ideally, puppeteer would just treat it as a normal 404 and not load the asset -- then I would see in my screenshots that my fonts aren't loading.

I see that opts.waitUntilNetworkIdle is false by default.. So I'm not sure why puppeteer was stuck on this asset. I've tried goofing around in createServer to handle this but I didn't have much luck.

dferber90 commented 3 years ago

Thanks for sharing your findings. I vaguely remember dealing with waitUntilNetworkIdle to ensure the page is completely loaded before taking the screenshot. Otherwise you could get discrepancies more often due to network instability.

I don't recall whether I ended up making it part of the defaults or not as it's been quite a while since I worked on this 😅