-
Notifications
You must be signed in to change notification settings - Fork 30
Add unexpected toast message detection to Cypress tests #3147
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
base: develop
Are you sure you want to change the base?
Changes from all commits
fa11ddf
904e22a
7175a3a
a19ed04
57757ac
68d6090
03c98f6
7e6e7ba
c2e998c
6871a1b
d85c7a3
df14c91
27cc599
069bf47
e922417
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Override for window.it used for all tests, to check the final state after each test, to make sure that unexpected errors | ||
| // or states that may have happened during the test are caught. | ||
|
|
||
| const originalIt = window.it; | ||
|
|
||
| window.it = function (title, optionsOrFunction, fn) { | ||
| // Determine test function and options based on the arguments passed to it | ||
| const testFn = | ||
| typeof optionsOrFunction === "function" ? optionsOrFunction : fn; | ||
| const testOptions = | ||
| typeof optionsOrFunction === "object" ? { ...optionsOrFunction } : {}; | ||
|
|
||
| if (typeof testFn !== "function") { | ||
| // Call the original it function with the provided arguments | ||
| // This is necessary to make it.skip work correctly | ||
| return originalIt(title, optionsOrFunction, fn); | ||
| } | ||
|
|
||
| // Call the original it function with the modified test function and options | ||
| return originalIt(title, testOptions, function () { | ||
| testFn(); | ||
| cy.checkFinalState(); | ||
| }); | ||
| }; | ||
|
|
||
| // Add the original it.only and it.skip methods to the window object | ||
| // originalIt.only and originalIt.skip will use the overridden window.it function | ||
| window.it.only = originalIt.only; | ||
| window.it.skip = originalIt.skip; | ||
|
|
||
| /** | ||
| * Override for visit | ||
| * Checks final state before performing the visit, to make sure that unexpected errors that may have happened previously are caught. | ||
| */ | ||
| Cypress.Commands.overwrite("visit", (originalFn, url, options) => { | ||
| return cy | ||
| .wrap(null, { log: false }) | ||
| .then(() => cy.checkFinalState()) | ||
| .then(() => cy.log(`Visit ${url}`)) | ||
| .then(() => originalFn(url, options)); | ||
| }); | ||
|
|
||
| /** | ||
| * Override for reload | ||
| * Checks final state before performing the reload, to make sure that unexpected errors that may have happened previously are caught. | ||
| */ | ||
| Cypress.Commands.overwrite("reload", (originalFn, ...args) => { | ||
| return cy | ||
| .wrap(null, { log: false }) | ||
| .then(() => cy.checkFinalState()) | ||
| .then(() => cy.log("Reload")) | ||
| .then(() => originalFn(...args)); | ||
| }); | ||
|
Comment on lines
+31
to
+53
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cypress logs are changed quite a bit because of the overrides. e.g. After the overrides: This is the case because the It would be possible to suppress the logs triggered by Even though this would be possible I would suggests to not suppress the logs triggered by the Therefore I would suggest using the current log strategy. |
||
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.
🧩 Analysis chain
🏁 Script executed:
Repository: THM-Health/PILOS
Length of output: 50373
🏁 Script executed:
# First, examine the file in question head -30 tests/Frontend/support/commands/commandOverrides.jsRepository: THM-Health/PILOS
Length of output: 1216
🏁 Script executed:
Repository: THM-Health/PILOS
Length of output: 302
🏁 Script executed:
Repository: THM-Health/PILOS
Length of output: 296
🏁 Script executed:
Repository: THM-Health/PILOS
Length of output: 1562
🏁 Script executed:
Repository: THM-Health/PILOS
Length of output: 42
🏁 Script executed:
Repository: THM-Health/PILOS
Length of output: 2095
🏁 Script executed:
Repository: THM-Health/PILOS
Length of output: 1436
🏁 Script executed:
Repository: THM-Health/PILOS
Length of output: 1065
Preserve test context and return Cypress command chains in the
itwrapper.Line 21 calls
testFn()directly without forwarding its return value, and line 22 callscy.checkFinalState()but doesn't return its Cypress command chain. This causes two issues:testFn()returns a value (promise or otherwise), it's discarded, breaking tests that rely on return semantics.cy.checkFinalState()is async (usescy.url().then()internally), but since the wrapper doesn't return the chain, Mocha may not wait for it to complete, creating a race condition where the test finishes before final state validation runs.Proposed fix
🤖 Prompt for AI Agents