Integrating logs to testing.T
instance.
#77
stroiman
started this conversation in
Getting started tips
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When creating a
browser.Browser
, you have the capability to inject anslog.Logger
. You can easily inject a logger that will forward browser logs to the specific test instance, keeping relevant log output with failing tests.This actually helped find a bug in Gost-DOM.
The bug was elusive as through
setTimeout()
or friends don't propagate errors back to test code. But errors will be logged on the logger. But a JS error would normally indicate the system isn't doing what you think it should, and therefore a failing test would make sense.Gost-DOM will by default generate
Error
level logs on4xx status errors generates
Warning
level logs.2In my own test project, I created
TestingLogHandler
a valid implementation ofslog.Handler
that pass logs to thetesting.T
/B
instance; and triggers anError
report onError
level logs.The
allowErrors
provide escape hatch for cases where errors are allowed to occur; which I use in CSRF tests. HTMX throws on the HTTP responses; and I didn't prioritize UX for failed validation.This approached helped find a bug in Gost-DOM itself. HTMX swapping into an empty element failed, because the V8 version of
insertBefore
generated an error if only one argument was passed; the correct behaviour would have been to call the underlying Go version withnil
as the 2nd argumentLog strategy
In general, it the intention is that Gost-DOM logs at the following levels.
Debug
console.debug
/console.trace
(trace
not supported yet)Info
EventTarget
console.log
andconsole.info
Warning
console.warn
Error
console.error
Footnotes
At the time of writing this, non 2xx errors generate
Error
level logs - but the statement will be true from next release. ↩There is not "contract" for the contents of the structured log record; but I'd love to get feedback as to what kind of format would make sense. ↩
Beta Was this translation helpful? Give feedback.
All reactions