Closed bsideup closed 7 years ago
Are you running them with mocha? If so use the step level plugin instead of the scenario level plugin.
@cressie176 I am, but it doesn't work :(
Sorry, I see what you mean now. I'll take a look, but suspect this will be how mocha processes describe() and it() functions.
@cressie176 cool, thanks :) Let me know about the progress :)
@cressie176 figured out that if we flatten steps (i.e. expand steps) before container.steps
call, reporting works fine, so it something with done
call I guess
Example (I hope it's fine that I use generators and other modern features, but if it'll not be clear enough I can rewrite it):
function *flatten(steps) {
for (const step of steps) {
const pattern = /^Sing (.*?) (.*?) bottles$/;
const match = step.match(pattern);
if (match) {
const [ , num, color ] = match;
yield *flatten([
`Given ${num} ${color} bottles are standing on the wall`,
`When 1 ${color} bottle accidentally falls`,
`Then there are ${num - 1} ${color} bottles standing on the wall`
]);
}
else {
yield step;
}
}
}
new Yadda.FeatureFileSearch('./tests/features/').each(file => {
container.featureFile(file, feature => {
container.scenarios(feature.scenarios, scenario => {
container.steps([...flatten(scenario.steps)], (step, done) => {
yadda.run(step, done);
});
});
});
});
I think what's going on is as follows...
When you call container.featureFile, yadda parses the feature and calls
describe(feature.title, () => {
When you call container.scenarios, yadda iterates over the scenarios calling
describe(scenario.title, () => {
When you call container.steps, yadda iterates over the steps calling
it(step.text, () =>{
then runs the step. Written in pure mocha this would look like
const assert = require('assert')
describe('Mocha Asynchronous Example ', () => {
describe('10 bottles are standing on a wall', () => {
it('Given 10 green bottles are standing on the wall', () => {
assert(false)
})
})
})
When I run the pure mocha version I get the same problem
Mocha Asynchronous Example
10 bottles are standing on a wall
1) Given 10 green bottles are standing on the wall
0 passing (11ms)
1 failing
1) Mocha Asynchronous Example 10 bottles are standing on a wall Given 10 green bottles are standing on the wall:
AssertionError: false == true
+ expected - actual
-false
+true
at Context.it (test.js:28:13)
The only way I can think of resolving this is to write a custom mocha reporter. Not sure why you had different behaviour with flatten.
On a separate note, arrow functions don't work too well in step definitions, e.g.
library.when(/some step/, (cb) => {
cb()
}
They're fine until you want to share something between steps. Unfortunately the way to do this with yadda is to define a shared context which Yadda binds the step function to. You have to access it with this
, which of course has different behaviour with arrow functions.
@cressie176 flatten works because it will expand the step into the substeps so Mocha will receive multiple it
's.
@cressie176 it's
steps([...flatten(scenario.steps)], (step, done) => {
yadda.run(step, done);
});
otherwise flatten is not being called
Yep - I tried with and without, to generate the flatten.txt and normal.txt files. Just happened to commit the version without the call to flatten
ah, ok. Weird. I'll prepare an example repo, so you can play with it :)
Any luck?
Closing due to inactivity. Let me know if you want it reopened.
Hi!
steps executed with
yadda.run([]]
are rendered as a single step in the report. However, expanding them would be great so, in case of failure, user will be able to see which substep failed.