Description
Is your feature request related to a problem? Please describe.
The Before
hook is passed a testCase
object (ITestCaseHookParameter
type) that's not really designed with the user in mind.
For example, a user had to do this in order to access the cells from the examples table that the running scenario came from:
Before((testCase: ITestCaseHookParameter) => {
const examplesMap = new Map()
const scenarioId = testCase.pickle.astNodeIds[0]
const exampleId = testCase.pickle.astNodeIds[1]
const scenario = testCase.gherkinDocument.feature.children.find((child) => child.scenario.id === scenarioId)
const cells = scenario.scenario.examples[0].tableHeader.cells
const values = scenario.scenario.examples[0].tableBody.find((body) => body.id === exampleId)
cells.forEach((cell, index) => {
examplesSet.set(cell.value, values.cells[index].value)
})
console.log(examplesMap)
})
Describe the solution you'd like
I suggest we wrap this testCase
object with an API designed from the user's conceptual model of a running scenario - so containing any information we have about the current test status, but also containing easy access to the Gherkin source of the test case too. We do something like this in Ruby.
For example:
Before((scenario: RunningScenario) => {
console.log(scenario.exampleRow?.cells)
})
or
Before((scenario: RunningScenario) => {
console.log(scenario.feature.name)
})
but also
Before((scenario: RunningScenario) => {
console.log(scenario.result)
})
or
Before((scenario: RunningScenario) => {
console.log(scenario.steps[0].result)
})
Additional context
An additional benefit of this layer of indirection is that we insulate our underlying types from dependencies from user-land code, leaving us more free to change these internal types if we need to. Right now, we're exposing types from the messages
project right out to users, so if we want to change those messages we have large ripple effects.