Skip to content

Commit

Permalink
fix stacktraces for transpiled languages
Browse files Browse the repository at this point in the history
resolves #538
  • Loading branch information
charlierudolph committed Jul 1, 2016
1 parent b3cf879 commit 1d02c6a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
35 changes: 21 additions & 14 deletions features/compiler.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ Feature: compilers
"""
Feature:
Scenario:
Given this step passes
Given a step
"""


Scenario: CoffeeScript step definition
Scenario: CoffeeScript step definition (passing)
Given a file named "features/step_definitions/cucumber_steps.coffee" with:
"""
stepDefinitions = ->
@When /^this step passes$/, (callback) ->
callback()
@Given /^a step$/, ->
module.exports = stepDefinitions
"""
Expand All @@ -31,21 +30,29 @@ Feature: compilers
<duration-stat>
"""

Scenario: Pogoscript step definition
Given a file named "features/step_definitions/cucumber_steps.pogo" with:

Scenario: CoffeeScript step definition (failing)
Given a file named "features/step_definitions/cucumber_steps.coffee" with:
"""
step definitions () =
this.When r/^this step passes$/ @(callback)
callback()
stepDefinitions = ->
@Given /^a step$/, -> throw 'fail'
module.exports = step definitions
module.exports = stepDefinitions
"""
When I run cucumber.js with `--compiler pogo:pogo -f progress`
When I run cucumber.js with `--compiler coffee:coffee-script/register -f progress`
Then it outputs this text:
"""
.
F
1 scenario (1 passed)
1 step (1 passed)
Failures:
1) Scenario: - features/a.feature:2
Step: Given a step - features/a.feature:3
Step Definition: features/step_definitions/cucumber_steps.coffee:2
Message:
fail
1 scenario (1 failed)
1 step (1 failed)
<duration-stat>
"""
20 changes: 10 additions & 10 deletions lib/cucumber/support_code/library.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function Library(supportCodeDefinition) {
var Cucumber = require('../../cucumber');
var callsite = require('callsite');
var StackTrace = require('stacktrace-js');
var _ = require('lodash');

var listeners = [];
Expand Down Expand Up @@ -49,9 +49,9 @@ function Library(supportCodeDefinition) {
code = options;
options = {};
}
var site = callsite();
var line = site[1].getLineNumber();
var uri = site[1].getFileName() || 'unknown';
var stackframes = StackTrace.getSync();
var line = stackframes[1].getLineNumber();
var uri = stackframes[1].getFileName() || 'unknown';
var hook = builder(code, options, uri, line);
collection.push(hook);
};
Expand All @@ -62,9 +62,9 @@ function Library(supportCodeDefinition) {
code = options;
options = {};
}
var site = callsite();
var line = site[1].getLineNumber();
var uri = site[1].getFileName() || 'unknown';
var stackframes = StackTrace.getSync();
var line = stackframes[1].getLineNumber();
var uri = stackframes[1].getFileName() || 'unknown';
var stepDefinition = Cucumber.SupportCode.StepDefinition(name, options, code, uri, line);
stepDefinitions.push(stepDefinition);
},
Expand All @@ -78,9 +78,9 @@ function Library(supportCodeDefinition) {
handler = options;
options = {};
}
var site = callsite();
options.line = site[1].getLineNumber();
options.uri = site[1].getFileName() || 'unknown';
var stackframes = StackTrace.getSync();
options.line = stackframes[1].getLineNumber();
options.uri = stackframes[1].getFileName() || 'unknown';
var listener = Cucumber.Listener(options);
listener.setHandlerForEvent(eventName, handler);
self.registerListener(listener);
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
"node": ">=0.10"
},
"dependencies": {
"callsite": "^1.0.0",
"camel-case": "^3.0.0",
"cli-table": "^0.3.1",
"co": "^4.6.0",
Expand All @@ -116,7 +115,8 @@
"glob": "^7.0.0",
"is-generator": "^1.0.2",
"lodash": "^4.0.0",
"stack-chain": "^1.3.5"
"stack-chain": "^1.3.5",
"stacktrace-js": "^1.3.0"
},
"devDependencies": {
"ansi_up": "^1.3.0",
Expand All @@ -129,7 +129,6 @@
"jasmine": "^2.3.2",
"jshint": "^2.9.1",
"json-diff": "^0.3.1",
"pogo": "^0.10.0",
"rimraf": "^2.4.3",
"serve-static": "^1.10.0",
"sinon": "^1.17.3",
Expand Down

0 comments on commit 1d02c6a

Please sign in to comment.