import DataTable from 'cucumber/lib/models/data_table'; import isJson from './isJson'; export default function bindGherkinSteps(steps, definitions) { return steps.reduce((acc, step) => { const definition = definitions.find((def) => { return def.matchesStepName(step.text); }); const args = definition.pattern ? Array.from(definition.pattern.exec(step.text)).slice(1) : []; const stepArgs = [ ...args, ...step.dataTable ? [new DataTable(step.dataTable)] : [], ...step.docString ? [isJson(step.docString.content) ? JSON.parse(step.docString.content) : step.docString.content] : [] ]; const type = (step.keyword || '').trim().toLowerCase(); if (acc.last !== type && type !== 'and' && type !== 'but') { acc.last = type; } return { ...acc, [acc.last]: [ ...acc[acc.last] || [], { description: `${step.keyword}${step.text}`, ...step, code: definition.code, stepArgs } ] }; }, { last: 'given', given: [], when: [], then: [] }); }