| 96 | |
| 97 | // Create wrapper functions that capture the call context |
| 98 | const createStepFunction = stepType => { |
| 99 | return (step, fn) => { |
| 100 | // Capture the stack trace at the point where Given/When/Then is called |
| 101 | const callStack = new Error().stack |
| 102 | |
| 103 | // Find the caller (step definition file) in the stack |
| 104 | let callerInfo = 'unknown_file:1:1' |
| 105 | if (callStack) { |
| 106 | const stackLines = callStack.split('\n') |
| 107 | for (let i = 1; i < stackLines.length; i++) { |
| 108 | const line = stackLines[i] |
| 109 | if (line.includes('step_definitions') && (line.includes('.js') || line.includes('.mjs'))) { |
| 110 | // Extract file path and use line 3:1 as consistent reference (import line) |
| 111 | const match = line.match(/file:\/\/.*\/(step_definitions\/[^:]+):(\d+):(\d+)/) |
| 112 | if (match) { |
| 113 | callerInfo = `${match[1]}:3:1` // Use line 3:1 consistently (import line) |
| 114 | break |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | // Instead of using global currentStepFile, pass the caller info directly to addStep |
| 121 | return addStepWithCaller(step, fn, callerInfo) |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | // New function that accepts caller info directly |
| 126 | const addStepWithCaller = async (step, fn, callerInfo) => { |
no test coverage detected