-
Notifications
You must be signed in to change notification settings - Fork 605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug 1880118: Improve Cypress checkErrors
output
#6475
Bug 1880118: Improve Cypress checkErrors
output
#6475
Conversation
e3d7209
to
b23364a
Compare
b23364a
to
14a346d
Compare
14a346d
to
02f1cf6
Compare
frontend/packages/integration-tests-cypress/tests/crud/k8-openshift-cruds.spec.ts
Outdated
Show resolved
Hide resolved
c61c836
to
e5b8b6e
Compare
/retest |
checkErrors
outputcheckErrors
output
e5b8b6e
to
5b65430
Compare
5b65430
to
783e4e3
Compare
Hi @spadgett, PR paired down to just update |
checkErrors
outputcheckErrors
output
@@ -59,7 +59,13 @@ Cypress.Commands.add('testA11y', (target: string) => { | |||
export const checkErrors = () => | |||
cy.window().then((win) => { | |||
if (win.windowError) { | |||
throw new Error(`window/js runtime error detected: ${win.windowError}`); | |||
throw new Error( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does throw win.windowError
work instead of creating a new Error
? Or adding an assertion that windowError
is nullish?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm...I had tried it in the past and it didn't work, but I haven't tried it since I truley changed win.windowError
to be an Error
not an Event
. I'll try to throw it again now that it's a true Error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw win.windowError
results in the following; we lose stack-trace, but since it's minified, not sure how useful it is:
ReferenceError: i is not defined
As opposed to throwing new Error w/ JSON.stringify & \n
processing:
window error detected: {
"message": "i is not defined",
"stack": "ReferenceError: i is not defined
at http://localhost:9000/static/main-35bf7a55e8c0461351e2.js:102081:5
at renderWithHooks (http://localhost:9000/static/vendors~main-47b21d89223a2a918b47.js:371358:18)
at mountIndeterminateComponent (http://localhost:9000/static/vendors~main-47b21d89223a2a918b47.js:373592:13)
at beginWork$1 (http://localhost:9000/static/vendors~main-47b21d89223a2a918b47.js:374736:16)
at HTMLUnknownElement.callCallback (http://localhost:9000/static/vendors~main-47b21d89223a2a918b47.js:356597:14)
at Object.invokeGuardedCallbackDev (http://localhost:9000/static/vendors~main-47b21d89223a2a918b47.js:356647:16)
at invokeGuardedCallback (http://localhost:9000/static/vendors~main-47b21d89223a2a918b47.js:356704:31)
at beginWork$$1 (http://localhost:9000/static/vendors~main-47b21d89223a2a918b47.js:379467:7)
at performUnitOfWork (http://localhost:9000/static/vendors~main-47b21d89223a2a918b47.js:378458:12)
at workLoopSync (http://localhost:9000/static/vendors~main-47b21d89223a2a918b47.js:378435:22)"
}
frontend/public/components/app.jsx
Outdated
window.windowError = error; | ||
}; | ||
window.onunhandledrejection = (promiseRejectionEvent) => { | ||
const error = new Error(`unhandled promise rejection: ${promiseRejectionEvent.reason}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this isn't already an error, maybe we just leave window.windowError
as Error | Event
and just check that it's not defined in Cypress rather than trying to rethrow it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we'd see any output for promiseRejectionEvent
in Cypress if we did that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: previously the window.windowError
was either an ErrorEvent
or promiseRejectionEvent
, it never was an Error
. I had to change the method signiture params in order to get the Error
: window.onerror = (message, source, lineno, colno, --->error<----)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do know that when window.windowError
was a promiseRejectionEvent
, throwing it didn't produce any output in headless. I believe it has to be an Error
. I believe I even tried doing window.dispatch(..)
when it was a promiseRejectionEvent
, but it didn't produce any output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, you wouldn't throw the event. You would check that it's not null and log the content (if not already logged by Cypress).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idk, I feel casting all into an Error
and just handling/throwing the Error
(directly or recreating w/ formatting), to me seems more straight forward.
Unless you are saying we should log the promiseRejectionEvent
, not throw an Error? So that the cypress tests won't fail on a promiseRejectionEvent
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm saying we have an assertion that causes the test to fail if windowError
is never null. Something like
expect(win.windowError).to.not.exist;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, tried
assert.isNull(
win.windowError,
`${(win.windowError as PromiseRejectionEvent).reason || (win.windowError as Error).message} ${
(win.windowError as Error).stack
}`
Which, in addition to the message (2nd arg in assert(..)), also output the tested object. Unfortunately, since window
is part of the PromiseRejectionEvent, it gets spit out along with a lot of other attributes:
2) Monitoring: Alerts
"after each" hook for "creates and expires a Silence":
path /silence_WRONG_URL/63646b85-b4a6-4ead-8a35-609a77317edf was not found undefined: expected { isTrusted: [Getter],
promise: {},
reason: 'path /silence_WRONG_URL/63646b85-b4a6-4ead-8a35-609a77317edf was not found',
NONE: 0,
CAPTURING_PHASE: 1,
AT_TARGET: 2,
BUBBLING_PHASE: 3,
type: 'unhandledrejection',
target:
{ parent:
{ parent: [Circular],
opener: null,
top: [Circular],
length: 2,
frames: [Circular],
closed: false,
location: [Object],
self: [Circular],
window: [Circular],
document: [Getter],
name: [Getter/Setter],
customElements: [Getter],
history: [Getter],
locationbar: [Getter/Setter],
menubar: [Getter/Setter],
personalbar: [Getter/Setter],
scrollbars: [Getter/Setter],
statusbar: [Getter/Setter],
toolbar: [Getter/Setter],
status: [Getter/Setter],
frameElement: [Getter],
navigator: [Getter],
origin: [Getter/Setter],
external: [Getter/Setter],
screen: [Getter/Setter],
innerWidth: [Getter/Setter],
innerHeight: [Getter/Setter],
scrollX: [Getter/Setter],
pageXOffset: [Getter/Setter],
scrollY: [Getter/Setter],
pageYOffset: [Getter/Setter],
visualViewport: [Getter/Setter],
screenX: [Getter/Setter],
screenY: [Getter/Setter],
outerWidth: [Getter/Setter],
outerHeight: [Getter/Setter],
devicePixelRatio: [Getter/Setter],
clientInformation: [Getter/Setter],
...
...
-- additional two screens worth of output ---
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest code I think moves closer to what your after. Changed the assertion so it doesn't ouput entire contents of win.windowError
. It does output ...: expected false to be true
which doesn't add any value:
assert.isTrue(
win.windowError === null,
`window error detected: ${(win.windowError as PromiseRejectionEvent).reason ||
(win.windowError as Error).message} ${
(win.windowError as Error).stack
? (win.windowError as Error).stack.replace(/\\n/g, '\n')
: ''
}`,
);
Produces:
...when windowError is a PromiseRejectionEvent:
2) Monitoring: Alerts
"after each" hook for "creates and expires a Silence":
AssertionError: window error detected: path /silence_WRONG_URL/b0ef08c1-e09c-41ab-a046-761d47a71bee was not found : expected false to be true
...when windowError is an Error:
2) Monitoring: Alerts
"after each" hook for "creates and expires a Silence":
window error detected: i is not defined ReferenceError: i is not defined
at http://localhost:9000/static/main-66d801b01502734ad2c0.js:96412:5
at renderWithHooks (http://localhost:9000/static/vendors~main-9d6cea73c651a7e7c901.js:377121:18)
at mountIndeterminateComponent (http://localhost:9000/static/vendors~main-9d6cea73c651a7e7c901.js:379355:13)
at beginWork$1 (http://localhost:9000/static/vendors~main-9d6cea73c651a7e7c901.js:380499:16)
at HTMLUnknownElement.callCallback (http://localhost:9000/static/vendors~main-9d6cea73c651a7e7c901.js:362360:14)
at Object.invokeGuardedCallbackDev (http://localhost:9000/static/vendors~main-9d6cea73c651a7e7c901.js:362410:16)
at invokeGuardedCallback (http://localhost:9000/static/vendors~main-9d6cea73c651a7e7c901.js:362467:31)
at beginWork$$1 (http://localhost:9000/static/vendors~main-9d6cea73c651a7e7c901.js:385230:7)
at performUnitOfWork (http://localhost:9000/static/vendors~main-9d6cea73c651a7e7c901.js:384221:12)
at workLoopSync (http://localhost:9000/static/vendors~main-9d6cea73c651a7e7c901.js:384198:22): expected false to be true
The only way to generate output in headless in afterEach
is either throwing an Error or failing an assertion. cy.task('log',' ...)
which uses console.log
doesn't output anything :-(
checkErrors
outputcheckErrors
output
@dtaylor113: This pull request references Bugzilla bug 1880118, which is valid. The bug has been updated to refer to the pull request using the external bug tracker. 3 validation(s) were run on this bug
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
783e4e3
to
a477405
Compare
/retest |
a477405
to
8428b40
Compare
8428b40
to
cdbda17
Compare
}` | ||
: 'no window error detected'; | ||
|
||
assert.isTrue(win.windowError === null, assertMsg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't check specifically for null. You want to handle undefined as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
? `window error detected: ${(win.windowError as PromiseRejectionEvent).reason || | ||
(win.windowError as Error).message} ${ | ||
(win.windowError as Error).stack | ||
? (win.windowError as Error).stack.replace(/\\n/g, '\n') | ||
: '' | ||
}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too much on one line. I'd pull this out into a helper. Something like
const formatWindowError = (windowError: Error | PromiseRejectionEvent) => {
const { reason } = windowError as PromiseRejectionEvent;
if (reason) {
return reason;
}
const { message, stack } = windowError as Error;
const formattedStack = stack?.replace(/\\n/g, '\n');
return `${message} ${formattedStack}`;
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, fixed.
throw new Error(`window/js runtime error detected: ${win.windowError}`); | ||
} | ||
const assertMsg = | ||
win.windowError !== null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle undefined
as well.
win.windowError !== null | |
win.windowError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
cdbda17
to
2c4b596
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dtaylor113, spadgett The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest Please review the full test history for this PR and help us cut down flakes. |
1 similar comment
/retest Please review the full test history for this PR and help us cut down flakes. |
@dtaylor113: All pull requests linked via external trackers have merged: Bugzilla bug 1880118 has been moved to the MODIFIED state. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
This PR updates our usage of
window.windowError
inapp.js
and also improves CypresscheckErrors()
output: