-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1.2.1 regression: dont crash if there is a single stackframe #605
Changes from 5 commits
f370fe0
a44b62c
0c6c555
b16107d
ad11745
a4764db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Feature: Custom stack trace | ||
|
||
Scenario: Error.prepareStackTrace override | ||
Given a file named "features/a.feature" with: | ||
""" | ||
Feature: Some feature | ||
Scenario: Some scenario | ||
Given I override Error.prepareStackTrace | ||
""" | ||
Given a file named "features/step_definitions/cucumber_steps.js" with: | ||
""" | ||
var cucumberSteps = function() { | ||
this.When(/^I override Error.prepareStackTrace$/, function() { | ||
Error.prepareStackTrace = function() { | ||
return 'Custom message'; | ||
} | ||
}); | ||
}; | ||
module.exports = cucumberSteps; | ||
""" | ||
When I run cucumber.js | ||
Then it outputs this text: | ||
""" | ||
Feature: Some feature | ||
|
||
Scenario: Some scenario | ||
✓ Given I override Error.prepareStackTrace | ||
|
||
1 scenario (1 passed) | ||
1 step (1 passed) | ||
<duration-stat> | ||
""" | ||
And the exit status should be 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,15 @@ function Library(supportCodeDefinition) { | |
}); | ||
} | ||
|
||
function getStackframe() { | ||
var stackframes = StackTrace.getSync(); | ||
if (stackframes.length > 2) { | ||
return stackframes[2]; | ||
} else { | ||
return stackframes[0]; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use lodash's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually can this just be simplified to
|
||
} | ||
|
||
var self = { | ||
lookupBeforeHooksByScenario: function lookupBeforeHooksByScenario(scenario) { | ||
return self.lookupHooksByScenario(beforeHooks, scenario); | ||
|
@@ -53,9 +62,9 @@ function Library(supportCodeDefinition) { | |
code = options; | ||
options = {}; | ||
} | ||
var stackframes = StackTrace.getSync(); | ||
var line = stackframes[1].getLineNumber(); | ||
var uri = stackframes[1].getFileName() || 'unknown'; | ||
var stackframe = getStackframe(); | ||
var line = stackframe.getLineNumber(); | ||
var uri = stackframe.getFileName() || 'unknown'; | ||
var hook = builder(code, options, uri, line); | ||
collection.push(hook); | ||
}; | ||
|
@@ -66,9 +75,9 @@ function Library(supportCodeDefinition) { | |
code = options; | ||
options = {}; | ||
} | ||
var stackframes = StackTrace.getSync(); | ||
var line = stackframes[1].getLineNumber(); | ||
var uri = stackframes[1].getFileName() || 'unknown'; | ||
var stackframe = getStackframe(); | ||
var line = stackframe.getLineNumber(); | ||
var uri = stackframe.getFileName() || 'unknown'; | ||
var stepDefinition = Cucumber.SupportCode.StepDefinition(name, options, code, uri, line); | ||
stepDefinitions.push(stepDefinition); | ||
}, | ||
|
@@ -82,9 +91,9 @@ function Library(supportCodeDefinition) { | |
handler = options; | ||
options = {}; | ||
} | ||
var stackframes = StackTrace.getSync(); | ||
options.line = stackframes[1].getLineNumber(); | ||
options.uri = stackframes[1].getFileName() || 'unknown'; | ||
var stackframe = getStackframe(); | ||
options.line = stackframe.getLineNumber(); | ||
options.uri = stackframe.getFileName() || 'unknown'; | ||
var listener = Cucumber.Listener(options); | ||
listener.setHandlerForEvent(eventName, handler); | ||
self.registerListener(listener); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't fail for me on master. I would expect you to need to override it before
this.When()
gets called as that is when the stacktrace is captured.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@charlierudolph my bad, it failed for me but because of the missing
✓
which I didn't see initially. I've just pushed an update for the test which this time I made sure were giving the error on master: