Closed chendachao closed 8 years ago
Hi,
In order to help you I need small sample of code that works incorrectly. Please, post it here.
My apologise for repond so late, here is a sample.
The first issue is it will run login's scenario.Before
and todo's scenario.Before
and login's steps.
login scenario.Before -> todo scenario.Before -> login when
,
I think correct execute order should be login scenario.Before -> login when -> todo scenario.After
,
when we run login steps, hooks should refer to login's but not todo's.
The second is if we add more than one scenario.Before
there will be duplicate outputs in console, please see below picture
Best regards.
Larry.
Hi,
There are a couple of issues. First, Before/After hooks are output to console by mistake. I will fix that. My intent was to output only steps to console. Second, before/after hooks are not per feature they are global instead. This is how cucumber.js works. I do not think I could change that. However you could use tagged hooks to constraint hooks execution. Note, scenarios inherit features tags.
Hi Eugene,
Thanks for your support, that resolved my problem.
I have some advice to improve this plugin:
First is for the output, I suggest you to take a look at another karma plugin called karma-jasmine-feature which convert Gherkin to Jasmine suites, here is a snapshot: .
My second suggestion is maybe you can include webpack, and let it support node JS like syntax:
module.exports = function () {
this.World = require('../support/world.js');
///// Your step definitions /////
// use this.Given(), this.When() and this.Then() to declare step definitions
this.Given(/^a variable set to (\d+)$/, function (number) {
this.setTo(number);
});
this.When(/^I increment the variable by (\d+)$/, function (number) {
this.incrementBy(number);
});
this.Then(/^the variable should contain (\d+)$/, function (number) {
if (this.variable != parseInt(number))
throw new Error('Variable should contain ' + number +
' but it contains ' + this.variable + '.');
});
};
Thanks again for your great work.
Thanks for your suggestions.
webpack (or other things like that) is not included deliberately because it is not the only option. Other options are system.js, require.js, browserify, etc. It is up to developer to choose one of them and use together with karma-cucumber-js plugin.
For "pretty" output karma-cucumber-js plugin generates HTML report (on your screenshot it is on the left). Feature/scenarios are collapsible, failing scenarios are expanded by default.
Note, official Cucumber flavor for Javascript is cucumber.js. I suggest you to ignore libs like karma-jasmine-feature, because they are not cucumber.js based. cucumber.js supports node.js and browsers and it is the most popular BDD tool for JavaScript.
Well sounds reasonable.
Hi Eugene,
First I want to thank you for create a so useful tool, we are going to use it for BDD tests.
But I found there is a big issue, when we add hooks like scenario.Before and scenario.After, the hooks will execute in every step. Which just like we put all the steps together, thus will make our code disorganized and it's hard to tear down some variables.
I guess it caused by we add all steps first and then look all of them to execute.
Can you help to take a look?
Finally I think if you can fix this issue, your plugin will be one of most great one.