Skip to content

Commit

Permalink
drop lines until __cypress/tests rather than just __cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
cacieprins committed Jan 10, 2025
1 parent 6106400 commit 877d8b2
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/driver/src/cypress/stack_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,16 @@ const stackWithUserInvocationStackSpliced = (err, userInvocationStack): StackAnd
}
}

type InvocationDetails = MessageLineDetail | {}
type InvocationDetails = {
absoluteFile?: string
column?: number
line?: number
originalFile?: string
relativeFile?: string
}

const getInvocationDetails = (specWindow, config) => {
// used to determine codeframes for hook/test/etc definitions rather than command invocations
const getInvocationDetails = (specWindow, config): InvocationDetails | undefined => {
if (specWindow.Error) {
let stack = (new specWindow.Error()).stack

Expand All @@ -120,7 +127,11 @@ const getInvocationDetails = (specWindow, config) => {
// firefox and chrome throw stacks that include lines from cypress
// So we drop the lines until we get to the spec stackframe (includes __cypress)
if (specWindow.Cypress) {
stack = stackWithLinesDroppedFromMarker(stack, '__cypress', true)
// The stack includes frames internal to cypress, after the spec stackframe. In order
// to determine the invocation details, the stack needs to be parsed and trimmed.

// in Chrome and Firefox, the spec stackframe includes the pattern, '__cypress/tests'.
stack = stackWithLinesDroppedFromMarker(stack, '__cypress/tests', true)
}

const details: InvocationDetails = getSourceDetailsForFirstLine(stack, config('projectRoot')) || {};
Expand Down

0 comments on commit 877d8b2

Please sign in to comment.