Skip to content

Commit

Permalink
fix all vite ct error specs
Browse files Browse the repository at this point in the history
  • Loading branch information
cacieprins committed Dec 13, 2024
1 parent 69b7f6b commit ddce890
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
29 changes: 9 additions & 20 deletions packages/driver/src/cypress/error_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ const getUserInvocationStack = (err, state) => {

if (!userInvocationStack) return

// In CT with vite, the user invocation stack includes internal cypress code, so clean it up

// remove lines that are included _prior_ to the first userland line
userInvocationStack = $stackUtils.stackWithLinesDroppedFromMarker(userInvocationStack, '/__cypress', true)

// remove lines that are included _after and including_ the replacement marker
userInvocationStack = $stackUtils.stackPriorToReplacementMarker(userInvocationStack)

if (
isCypressErr(err)
|| isAssertionErr(err)
Expand Down Expand Up @@ -451,28 +459,9 @@ const enhanceStack = ({ err, userInvocationStack, projectRoot }: {
userInvocationStack?: any
projectRoot?: any
}) => {
let invocationStack = userInvocationStack

if (err.codeFrame === undefined) {
//console.log('enhanceStack - no codeframe, so dropping lines til marker')
err.stack = $stackUtils.stackWithLinesDroppedFromMarker(err.stack, '/__cypress', true)
// sometimes the userInvocationStack has internals, so drop them
invocationStack = userInvocationStack ? $stackUtils.stackWithLinesDroppedFromMarker(userInvocationStack, '/__cypress', true) : undefined
// sometimes the userInvocationStack includes the replacement marker, so drop everything after that
//invocationStack = invocationStack ? $stackUtils.stackPriorToReplacementMarker(invocationStack) : undefined
}

const { stack, index } = preferredStackAndCodeFrameIndex(err, invocationStack)

//console.log('enhanceStack stack', stack)
const { stack, index } = preferredStackAndCodeFrameIndex(err, userInvocationStack)
const { sourceMapped, parsed } = $stackUtils.getSourceStack(stack, projectRoot)

// console.log('enhanceStack err', err)
// console.log('enhanceStack userInvocationStack', userInvocationStack)
// console.log('enhanceStack projectRoot', projectRoot)
// console.log('enhanceStack parsed', parsed)
// console.log('enhanceStack sourceMapped', sourceMapped)

err.stack = sourceMapped
err.parsedStack = parsed
err.codeFrame = $stackUtils.getCodeFrame(err, index)
Expand Down
10 changes: 8 additions & 2 deletions packages/driver/src/cypress/stack_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ const stackWithReplacementMarkerLineRemoved = (stack) => {
})
}

const stackPriorToReplacementMarker = (stack) => {
return _.chain(stack).split('\n')
.takeWhile((line) => !line.includes(STACK_REPLACEMENT_MARKER))
.join('\n')
.value()
}

export type StackAndCodeFrameIndex = {
stack: string
index?: number
Expand Down Expand Up @@ -106,7 +113,6 @@ const getInvocationDetails = (specWindow, config) => {
if (specWindow.Error) {
let stack = (new specWindow.Error()).stack

console.log('getInvocationDetails stack', stack)
// note: specWindow.Cypress can be undefined or null
// if the user quickly reloads the tests multiple times

Expand Down Expand Up @@ -209,7 +215,6 @@ const getCodeFrame = (err, stackIndex) => {

const stackLine = getCodeFrameStackLine(err, stackIndex)

console.log('getCodeFrame', { stack: err.stack, stackIndex, stackLine })
if (!stackLine) return

const { fileUrl, originalFile } = stackLine
Expand Down Expand Up @@ -514,6 +519,7 @@ export default {
stackWithLinesDroppedFromMarker,
stackWithoutMessage,
stackWithReplacementMarkerLineRemoved,
stackPriorToReplacementMarker,
stackWithUserInvocationStackSpliced,
captureUserInvocationStack,
getInvocationDetails,
Expand Down

0 comments on commit ddce890

Please sign in to comment.