Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3bb1471
fix: (studio) remove `itGrep` lines from stack trace when determining…
astone123 Oct 10, 2025
b6bc0f5
Merge branch 'develop' into astone123/fix-itgrep-trace
astone123 Oct 28, 2025
926e1fc
handle .only and suites
astone123 Nov 3, 2025
49165cf
Merge branch 'develop' into astone123/fix-itgrep-trace
astone123 Nov 3, 2025
61311ee
Merge branch 'develop' into astone123/fix-itgrep-trace
astone123 Nov 3, 2025
0a8de00
Merge branch 'develop' into astone123/fix-itgrep-trace
astone123 Nov 6, 2025
a1480d8
for test block hooks, trim the stack to find the invocation details
astone123 Nov 6, 2025
36064a6
Merge branch 'develop' into astone123/fix-itgrep-trace
astone123 Nov 6, 2025
65d656c
fix stop only
astone123 Nov 6, 2025
c0fb620
fix cypress object access
astone123 Nov 7, 2025
96a9a10
Merge branch 'develop' into astone123/fix-itgrep-trace
astone123 Nov 7, 2025
d0dfb88
update comment to use generic host
astone123 Nov 11, 2025
5d5cc2d
Merge branch 'develop' into astone123/fix-itgrep-trace
astone123 Nov 11, 2025
79c51da
Merge branch 'develop' into astone123/fix-itgrep-trace
astone123 Nov 11, 2025
a7e5bb2
Update packages/driver/src/cypress/stack_utils.ts
astone123 Nov 12, 2025
7bb0f76
Update packages/driver/src/cypress/stack_utils.ts
astone123 Nov 12, 2025
42d6495
Update packages/driver/src/cypress/mocha.ts
astone123 Nov 12, 2025
1929cba
Update packages/driver/src/cypress/stack_utils.ts
astone123 Nov 12, 2025
ec9dad3
Update packages/driver/src/cypress/stack_utils.ts
astone123 Nov 12, 2025
85756f0
feedback
astone123 Nov 12, 2025
1bc1d68
Merge branch 'develop' into astone123/fix-itgrep-trace
astone123 Nov 12, 2025
4a53ed1
changelog entry
astone123 Nov 12, 2025
cde2e2c
remove unnecessary test, add driver integration tests
astone123 Nov 13, 2025
badf190
fix .only
astone123 Nov 13, 2025
d7f64f0
update test name
astone123 Nov 13, 2025
76e2319
Merge branch 'develop' into astone123/fix-itgrep-trace
astone123 Nov 13, 2025
31af0fb
fix types
astone123 Nov 13, 2025
dbe8c6f
add integration test
astone123 Nov 14, 2025
e9d72cf
logic and test updates
astone123 Nov 14, 2025
4df6616
Merge branch 'develop' into astone123/fix-itgrep-trace
astone123 Nov 14, 2025
1dfe50c
fix types
astone123 Nov 14, 2025
6fa202f
fix test
astone123 Nov 14, 2025
50418a8
only modify stacks for e2e tests
astone123 Nov 14, 2025
eecaaff
fix integration test
astone123 Nov 17, 2025
1d324d1
update stack utils logic
astone123 Nov 17, 2025
0f3c72b
update unit tests, add component test
astone123 Nov 17, 2025
5553ddf
Merge branch 'develop' into astone123/fix-itgrep-trace
astone123 Nov 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/driver/src/cypress/stack_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,27 @@ const stackWithLinesRemoved = (stack, cb) => {
return unsplitStack(messageLines, remainingStackLines)
}

const stackWithGrepLinesRemoved = (stack) => {
return stackWithLinesRemoved(stack, (lines) => {
// Remove any lines containing 'itGrep' first
let cleanedLines = _.reject(lines, (line) => line.includes('itGrep'))

// 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 (
cleanedLines.length > 0 &&
!(
cleanedLines[0].trim().startsWith('at eval') ||
cleanedLines[0].trim().startsWith('at Suite.eval')
)
) {
cleanedLines.shift()
}

return cleanedLines
})
}

const stackWithLinesDroppedFromMarker = (stack, marker, includeLast = false) => {
return stackWithLinesRemoved(stack, (lines) => {
// drop lines above the marker
Expand Down Expand Up @@ -146,6 +167,13 @@ const getInvocationDetails = (specWindow, sourceMapProjectRoot: string): Invocat
}
}

// if the stack includes the 'itGrep' function, this suggests that the user has registered
// the @cypress/grep plugin. In this case, we need to remove the lines that include 'itGrep'
// so that the first line in the stack is the spec invocation.
if (stack.includes('itGrep')) {
stack = stackWithGrepLinesRemoved(stack)
}

const details: Omit<InvocationDetails, 'stack'> = getSourceDetailsForFirstLine(stack, sourceMapProjectRoot) || {}

;(details as any).stack = stack
Expand Down
78 changes: 78 additions & 0 deletions packages/driver/test/unit/cypress/stack_utils.spec.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like any of these unit tests test the firefox workflow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added unit tests for firefox stacks

Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,84 @@ describe('stack_utils', () => {
})
})
}

it('returns the correct invocation details for a grep stack trace', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('returns the correct invocation details for a grep stack trace', () => {
it('returns the correct invocation details for a test with a stack that needs to be trimmed', () => {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

const stack = `Error\n
at itGrep (http://localhost:3000/__cypress/tests?p=cypress/support/e2e.js:444:14)\n
at eval (http://localhost:3000/__cypress/tests?p=cypress/e2e/spec.cy.js:14:1)\n
at eval (http://localhost:3000/__cypress/tests?p=cypress/e2e/spec.cy.js:18:12)\n
at eval (<anonymous>)\n
at eval (cypress:///../driver/src/cypress/script_utils.ts:38:23)`

class GrepError {
get stack () {
return stack
}
}

stack_utils.getInvocationDetails(
{ Error: GrepError, Cypress: {} },
config,
)

expect(source_map_utils.getSourcePosition).toHaveBeenCalledWith('http://localhost:3000/__cypress/tests?p=cypress/e2e/spec.cy.js', expect.objectContaining({
column: 1,
line: 14,
file: 'http://localhost:3000/__cypress/tests?p=cypress/e2e/spec.cy.js',
}))
})

it('returns the correct invocation details for a grep stack trace for suites', () => {
const stack = `Error
at itGrep (http://localhost:3000/__cypress/tests?p=cypress/support/e2e.js:444:14)
at context.it.only (cypress:///../driver/node_modules/mocha/lib/interfaces/bdd.js:98:46)
at createRunnable (cypress:///../driver/src/cypress/mocha.ts:126:31)
at itGrep.eval [as only] (cypress:///../driver/src/cypress/mocha.ts:187:14)
at Suite.eval (http://localhost:3000/__cypress/tests?p=cypress/e2e/spec.cy.js:12:6)`

class GrepError {
get stack () {
return stack
}
}

stack_utils.getInvocationDetails(
{ Error: GrepError, Cypress: {} },
config,
)

expect(source_map_utils.getSourcePosition).toHaveBeenCalledWith('http://localhost:3000/__cypress/tests?p=cypress/e2e/spec.cy.js', expect.objectContaining({
column: 6,
line: 12,
file: 'http://localhost:3000/__cypress/tests?p=cypress/e2e/spec.cy.js',
}))
})

it('returns the correct invocation details for a grep stack trace for tests with only', () => {
const stack = `Error
at itGrep (http://localhost:3000/__cypress/tests?p=cypress/support/e2e.js:444:14)
at context.it.only (cypress:///../driver/node_modules/mocha/lib/interfaces/bdd.js:98:46)
at createRunnable (cypress:///../driver/src/cypress/mocha.ts:126:31)
at itGrep.eval [as only] (cypress:///../driver/src/cypress/mocha.ts:187:14)
at eval (http://localhost:3000/__cypress/tests?p=cypress/e2e/spec.cy.js:11:4)`

class GrepError {
get stack () {
return stack
}
}

stack_utils.getInvocationDetails(
{ Error: GrepError, Cypress: {} },
config,
)

expect(source_map_utils.getSourcePosition).toHaveBeenCalledWith('http://localhost:3000/__cypress/tests?p=cypress/e2e/spec.cy.js', expect.objectContaining({
column: 4,
line: 11,
file: 'http://localhost:3000/__cypress/tests?p=cypress/e2e/spec.cy.js',
}))
})
})

describe('normalizedUserInvocationStack', () => {
Expand Down
Loading