-
-
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
Issue: 997 Start of BeforeStep functionality #1058
Changes from 1 commit
0abf18e
faa43e7
65c012a
47ffd9a
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 |
---|---|---|
|
@@ -120,8 +120,9 @@ describe('RerunFormatter', () => { | |
|
||
it('outputs the references needed to run the scenarios again', function() { | ||
expect(this.output).to.eql( | ||
`${this.feature1Path}:1${separator.expected}${this | ||
.feature2Path}:2` | ||
`${this.feature1Path}:1${separator.expected}${ | ||
this.feature2Path | ||
}:2` | ||
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. I was getting a linting error here. |
||
) | ||
}) | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import PickleFilter from '../pickle_filter' | ||
import StepDefinition from './step_definition' | ||
|
||
export default class TestStepHookDefinition extends StepDefinition { | ||
constructor(data) { | ||
super(data) | ||
this.pickleFilter = new PickleFilter({ | ||
tagExpression: this.options.tags, | ||
}) | ||
} | ||
|
||
appliesToTestCase({ pickle, uri }) { | ||
return this.pickleFilter.matches({ pickle, uri }) | ||
} | ||
|
||
getInvalidCodeLengthMessage() { | ||
return this.buildInvalidCodeLengthMessage('0 or 1', '2') | ||
} | ||
|
||
getInvocationParameters({ hookParameter }) { | ||
return [hookParameter] | ||
} | ||
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. I don't think these hooks need invocation parameters (like what is passed to before/after hooks) |
||
|
||
getValidCodeLengths() { | ||
return [0, 1, 2] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ export default class TestCaseRunner { | |
parameters: worldParameters, | ||
}) | ||
this.beforeHookDefinitions = this.getBeforeHookDefinitions() | ||
this.beforeStepHookDefinitions = this.getBeforeStepHookDefinitions() | ||
this.afterHookDefinitions = this.getAfterHookDefinitions() | ||
this.testStepIndex = 0 | ||
this.result = { | ||
|
@@ -91,6 +92,12 @@ export default class TestCaseRunner { | |
) | ||
} | ||
|
||
getBeforeStepHookDefinitions() { | ||
return this.supportCodeLibrary.beforeTestStepHookDefinitions.filter( | ||
stepHookDefinition => stepHookDefinition.appliesToTestCase(this.testCase) | ||
) | ||
} | ||
|
||
getStepDefinitions(step) { | ||
return this.supportCodeLibrary.stepDefinitions.filter(stepDefinition => | ||
stepDefinition.matchesStepName({ | ||
|
@@ -182,6 +189,12 @@ export default class TestCaseRunner { | |
}) | ||
} | ||
|
||
async runStepHooks(hookDefinitions, hookParameter) { | ||
await Promise.each(hookDefinitions, async hookDefinition => { | ||
await this.runHook(hookDefinition, hookParameter) | ||
}) | ||
} | ||
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. Thinking on this function, we are currently not adding the duration of the step hooks to the overall duration of the step. That should be testable with unit tests |
||
|
||
async runStep(step) { | ||
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. @charlierudolph BeforeStep/AfterStep are working. I do have questions about stacktrace reporting and duration calculation. |
||
const stepDefinitions = this.getStepDefinitions(step) | ||
if (stepDefinitions.length === 0) { | ||
|
@@ -199,7 +212,13 @@ export default class TestCaseRunner { | |
|
||
async runSteps() { | ||
await Promise.each(this.testCase.pickle.steps, async step => { | ||
// TODO handle failure | ||
await this.runStepHooks(this.beforeStepHookDefinitions, { | ||
sourceLocation: this.testCaseSourceLocation, | ||
pickle: this.testCase.pickle, | ||
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. Hmm. I don't expect the beforeStep would need these parameters. I think we could start with passing in only the step. The after step will end up getting the step and the stepResult. 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. will fix |
||
}) | ||
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. I think this should be within the call to 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. does it make sense that i move into the |
||
await this.aroundTestStep(() => this.runStep(step)) | ||
// TODO run after step hooks | ||
}) | ||
} | ||
} |
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.
Can we please put these new features in their own feature file? I think we will have enough new features by the end to warrant their own file. The world in hooks would get its own step hook feature
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.
Definitely