diff --git a/packages/driver/src/cypress/stack_utils.ts b/packages/driver/src/cypress/stack_utils.ts index 7cc04c11e12..778d957927c 100644 --- a/packages/driver/src/cypress/stack_utils.ts +++ b/packages/driver/src/cypress/stack_utils.ts @@ -63,6 +63,12 @@ const stackWithLinesRemoved = (stack, cb) => { return unsplitStack(messageLines, remainingStackLines) } +const stackWithGrepLinesRemoved = (stack) => { + return stackWithLinesRemoved(stack, (lines) => { + return _.reject(lines, (line) => line.includes('itGrep')) + }) +} + const stackWithLinesDroppedFromMarker = (stack, marker, includeLast = false) => { return stackWithLinesRemoved(stack, (lines) => { // drop lines above the marker @@ -149,6 +155,12 @@ const getInvocationDetails = (specWindow, config): InvocationDetails | undefined } } + // if the stack includes the 'itGrep' function, remove any lines that include it + // so that the first line in the stack is the spec invocation + if (stack.includes('itGrep')) { + stack = stackWithGrepLinesRemoved(stack) + } + const details: Omit = getSourceDetailsForFirstLine(stack, config('projectRoot')) || {}; (details as any).stack = stack diff --git a/packages/driver/test/unit/cypress/stack_utils.spec.ts b/packages/driver/test/unit/cypress/stack_utils.spec.ts index 1a912e88908..bd53889a6b9 100644 --- a/packages/driver/test/unit/cypress/stack_utils.spec.ts +++ b/packages/driver/test/unit/cypress/stack_utils.spec.ts @@ -64,6 +64,32 @@ describe('stack_utils', () => { }) }) } + + it('returns the correct invocation details for a grep stack trace', () => { + 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 ()\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', + })) + }) }) describe('normalizedUserInvocationStack', () => {