Skip to content

Commit 3bb1471

Browse files
committed
fix: (studio) remove itGrep lines from stack trace when determining invocationDetails
1 parent 04bd3f1 commit 3bb1471

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

packages/driver/src/cypress/stack_utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ const stackWithLinesRemoved = (stack, cb) => {
6363
return unsplitStack(messageLines, remainingStackLines)
6464
}
6565

66+
const stackWithGrepLinesRemoved = (stack) => {
67+
return stackWithLinesRemoved(stack, (lines) => {
68+
return _.reject(lines, (line) => line.includes('itGrep'))
69+
})
70+
}
71+
6672
const stackWithLinesDroppedFromMarker = (stack, marker, includeLast = false) => {
6773
return stackWithLinesRemoved(stack, (lines) => {
6874
// drop lines above the marker
@@ -149,6 +155,12 @@ const getInvocationDetails = (specWindow, config): InvocationDetails | undefined
149155
}
150156
}
151157

158+
// if the stack includes the 'itGrep' function, remove any lines that include it
159+
// so that the first line in the stack is the spec invocation
160+
if (stack.includes('itGrep')) {
161+
stack = stackWithGrepLinesRemoved(stack)
162+
}
163+
152164
const details: Omit<InvocationDetails, 'stack'> = getSourceDetailsForFirstLine(stack, config('projectRoot')) || {};
153165

154166
(details as any).stack = stack

packages/driver/test/unit/cypress/stack_utils.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,32 @@ describe('stack_utils', () => {
6464
})
6565
})
6666
}
67+
68+
it('returns the correct invocation details for a grep stack trace', () => {
69+
const stack = `Error\n
70+
at itGrep (http://localhost:3000/__cypress/tests?p=cypress/support/e2e.js:444:14)\n
71+
at eval (http://localhost:3000/__cypress/tests?p=cypress/e2e/spec.cy.js:14:1)\n
72+
at eval (http://localhost:3000/__cypress/tests?p=cypress/e2e/spec.cy.js:18:12)\n
73+
at eval (<anonymous>)\n
74+
at eval (cypress:///../driver/src/cypress/script_utils.ts:38:23)`
75+
76+
class GrepError {
77+
get stack () {
78+
return stack
79+
}
80+
}
81+
82+
stack_utils.getInvocationDetails(
83+
{ Error: GrepError, Cypress: {} },
84+
config,
85+
)
86+
87+
expect(source_map_utils.getSourcePosition).toHaveBeenCalledWith('http://localhost:3000/__cypress/tests?p=cypress/e2e/spec.cy.js', expect.objectContaining({
88+
column: 1,
89+
line: 14,
90+
file: 'http://localhost:3000/__cypress/tests?p=cypress/e2e/spec.cy.js',
91+
}))
92+
})
6793
})
6894

6995
describe('normalizedUserInvocationStack', () => {

0 commit comments

Comments
 (0)