Plant-Tracer / webapp

Client and Server for web-based JavaScript app
GNU Affero General Public License v3.0
0 stars 2 forks source link

Detecting JavaScript console errors and warns. #542

Open sbarber2 opened 3 weeks ago

sbarber2 commented 3 weeks ago

See #454

Browser console messages are maddeningly ephemeral and usually invisible.

We need 4 ways to handle JavaScript console errors and/or warns, since we are using (or plan to use) 4 different kinds of testing technology:

For Manual dev/test, we can try:

For the other three, see comments below.

sbarber2 commented 3 weeks ago

As a recent example, #566 occurred as an issue because no one noticed that module.export() works fine in node.js when running standalone Jest tests via node.js, but then throws an error in Chrome. The error didn't appear to affect operation of the app (because it was the last statement in the .js file and because it wasn't necessary in the browser app's design). But it was invisible to us during dev and test until I happened to open the browser console looking for a different issue.

So there are at least two use cases here:

sbarber2 commented 3 weeks ago

Ah, we can have Jest tests fail by overriding console.error (and/or console.warn?): https://stackoverflow.com/questions/28615293/is-there-a-jest-config-that-will-fail-tests-on-console-warn

Good or bad idea?: discuss at #571

(This probably would not have helped with #566 though, since Jest is by definition running in a simulated browser environment in a node.js process. But for other console issues, it could still be helpful to find some console errors/warnings this way.)

sbarber2 commented 3 weeks ago

If and when we start using Playwright for in-browser testing, here's a way to catch console errors.

sbarber2 commented 3 weeks ago

And here's a way to do this in selenium.

simsong commented 3 weeks ago

We have learned so much about this project, we should write an article for a CMQ that tells people who have skills from 1520 years ago how to get caught up to speed with the modern dev stack.

I wonder how much of the testing that we’ve implemented we would’ve gotten free with react. Does Joe know?

On Sun, Oct 13, 2024 at 8:47 AM Steve Barber @.***> wrote:

And here's a way https://stackoverflow.com/questions/4189312/capturing-javascript-error-in-selenium to do this in selenium.

— Reply to this email directly, view it on GitHub https://github.com/Plant-Tracer/webapp/issues/542#issuecomment-2408966713, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMFHLBPO6ER2ELY5SVRRD3Z3JTVXAVCNFSM6AAAAABPWT7VXCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMBYHE3DMNZRGM . You are receiving this because you are subscribed to this thread.Message ID: @.***>

joedinsmoor commented 3 weeks ago

I have some free time tomorrow, I can potentially draft a couple jest tests to catch console errors so that we can have an understanding of how it would work.