-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix: normalize test body invocationDetails from stack traces
#32699
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
Open
astone123
wants to merge
11
commits into
develop
Choose a base branch
from
astone123/fix-itgrep-trace
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+224
−15
Open
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3bb1471
fix: (studio) remove `itGrep` lines from stack trace when determining…
astone123 b6bc0f5
Merge branch 'develop' into astone123/fix-itgrep-trace
astone123 926e1fc
handle .only and suites
astone123 49165cf
Merge branch 'develop' into astone123/fix-itgrep-trace
astone123 61311ee
Merge branch 'develop' into astone123/fix-itgrep-trace
astone123 0a8de00
Merge branch 'develop' into astone123/fix-itgrep-trace
astone123 a1480d8
for test block hooks, trim the stack to find the invocation details
astone123 36064a6
Merge branch 'develop' into astone123/fix-itgrep-trace
astone123 65d656c
fix stop only
astone123 c0fb620
fix cypress object access
astone123 96a9a10
Merge branch 'develop' into astone123/fix-itgrep-trace
astone123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,53 @@ const stackWithLinesRemoved = (stack, cb) => { | |
| return unsplitStack(messageLines, remainingStackLines) | ||
| } | ||
|
|
||
| const stackWithWrappingLinesRemoved = (stack) => { | ||
| const modifiedStack = stackWithLinesRemoved(stack, (lines) => { | ||
| if (Cypress.isBrowser('chrome')) { | ||
| // There are cases where there are other lines in the stack trace before the invocation (eg. `context.it.only`, `createRunnable`, etc) | ||
| // Remove lines from the start until the top line starts with 'at eval' or 'at Suite.eval' so that we only keep the actual invocation line. | ||
| while ( | ||
| lines.length > 0 && | ||
| !( | ||
| lines[0].trim().startsWith('at eval') || | ||
| lines[0].trim().startsWith('at Suite.eval') | ||
| ) | ||
| ) { | ||
| lines.shift() | ||
| } | ||
| } else if (Cypress.isBrowser('firefox')) { | ||
| const isTestInvocationLine = (line: string) => { | ||
| const splitAtAt = line.split('@') | ||
|
|
||
| // firefox stacks traces look like: | ||
| // functionName@https://aicotravel.com/__cypress/tests?p=cypress/support/e2e.js:444:14 | ||
|
Contributor
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. maybe use a different url besides aicotravel in the docs here?
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. oops - meant to change that. Will update that to something else |
||
| // @https://aicotravel.com/__cypress/tests?p=cypress/e2e/spec.cy.js:43:3 | ||
| // @https://aicotravel.com/__cypress/tests?p=cypress/e2e/spec.cy.js:45:12 | ||
| // evalScripts/<@cypress:///../driver/src/cypress/script_utils.ts:38:23 | ||
| // | ||
| // the actual invocation details will be at the first line with no function name | ||
| return splitAtAt.length > 1 && splitAtAt[0].trim().length === 0 | ||
| } | ||
|
|
||
| while ( | ||
| lines.length > 0 && | ||
| !isTestInvocationLine(lines[0]) | ||
| ) { | ||
| lines.shift() | ||
| } | ||
| } | ||
|
|
||
| return lines | ||
| }) | ||
|
|
||
| // if we removed all the lines then something went wrong. return the original stack instead | ||
| if (modifiedStack.length === 0) { | ||
| return stack | ||
| } | ||
|
|
||
| return modifiedStack | ||
| } | ||
astone123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const stackWithLinesDroppedFromMarker = (stack, marker, includeLast = false) => { | ||
| return stackWithLinesRemoved(stack, (lines) => { | ||
| // drop lines above the marker | ||
|
|
@@ -124,7 +171,7 @@ type InvocationDetails = { | |
| } | ||
|
|
||
| // used to determine codeframes for hook/test/etc definitions rather than command invocations | ||
| const getInvocationDetails = (specWindow, sourceMapProjectRoot: string): InvocationDetails | undefined => { | ||
| const getInvocationDetails = (specWindow, sourceMapProjectRoot: string, type?: 'test-body'): InvocationDetails | undefined => { | ||
| if (specWindow.Error) { | ||
| let stack = (new specWindow.Error()).stack | ||
|
|
||
|
|
@@ -146,6 +193,11 @@ const getInvocationDetails = (specWindow, sourceMapProjectRoot: string): Invocat | |
| } | ||
| } | ||
|
|
||
| // if the hook is the test body, we will try to remove the lines that are not the actual invocation of the test | ||
| if (type === 'test-body') { | ||
| stack = stackWithWrappingLinesRemoved(stack) | ||
| } | ||
|
|
||
| const details: Omit<InvocationDetails, 'stack'> = getSourceDetailsForFirstLine(stack, sourceMapProjectRoot) || {} | ||
|
|
||
| ;(details as any).stack = stack | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
system-tests/project-fixtures/runner-specs/cypress/e2e/hooks/wrapped-it.cy.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| function myIt (name, fn) { | ||
| it(name, fn) | ||
| } | ||
|
|
||
| myIt('test 1', () => { | ||
| cy.log('testBody 1') | ||
| }) | ||
|
|
||
| myIt('test 2', () => { | ||
| cy.log('testBody 2') | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Bug: Fix Chrome stack normalization for Context.eval lines
The Chrome stack normalization logic only checks for lines starting with
at evalorat Suite.eval, but test invocation lines can also start withat Context.eval. This causes the function to incorrectly remove valid test invocation lines, potentially returning an empty stack or the wrong line. The condition should also check forat Context.evalto handle all test body invocation patterns.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 might be missing something, but from my testing, even if we use
context, the stack still containsSuite.eval. So I think this is fine