@cucumber/cucumber
Version:
The official JavaScript implementation of Cucumber.
89 lines • 3.17 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.assembleTestCases = assembleTestCases;
const value_checker_1 = require("../value_checker");
async function assembleTestCases(testRunStartedId, eventBroadcaster, newId, sourcedPickles, supportCodeLibrary) {
return sourcedPickles.map(({ gherkinDocument, pickle }) => {
const testCaseId = newId();
const fromBeforeHooks = makeBeforeHookSteps({
supportCodeLibrary,
pickle,
newId,
});
const fromStepDefinitions = makeSteps({
pickle,
supportCodeLibrary,
newId,
});
const fromAfterHooks = makeAfterHookSteps({
supportCodeLibrary,
pickle,
newId,
});
const testCase = {
testRunStartedId,
pickleId: pickle.id,
id: testCaseId,
testSteps: [
...fromBeforeHooks,
...fromStepDefinitions,
...fromAfterHooks,
],
};
eventBroadcaster.emit('envelope', { testCase });
return {
gherkinDocument,
pickle,
testCase,
};
});
}
function makeAfterHookSteps({ supportCodeLibrary, pickle, newId, }) {
return supportCodeLibrary.afterTestCaseHookDefinitions
.slice(0)
.reverse()
.filter((hookDefinition) => hookDefinition.appliesToTestCase(pickle))
.map((hookDefinition) => ({
id: newId(),
hookId: hookDefinition.id,
}));
}
function makeBeforeHookSteps({ supportCodeLibrary, pickle, newId, }) {
return supportCodeLibrary.beforeTestCaseHookDefinitions
.filter((hookDefinition) => hookDefinition.appliesToTestCase(pickle))
.map((hookDefinition) => ({
id: newId(),
hookId: hookDefinition.id,
}));
}
function makeSteps({ pickle, supportCodeLibrary, newId, }) {
return pickle.steps.map((pickleStep) => {
const stepDefinitions = supportCodeLibrary.stepDefinitions.filter((stepDefinition) => stepDefinition.matchesStepName(pickleStep.text));
return {
id: newId(),
pickleStepId: pickleStep.id,
stepDefinitionIds: stepDefinitions.map((stepDefinition) => stepDefinition.id),
stepMatchArgumentsLists: stepDefinitions.map((stepDefinition) => {
const result = stepDefinition.expression.match(pickleStep.text);
return {
stepMatchArguments: result.map((arg) => {
return {
group: mapArgumentGroup(arg.group),
parameterTypeName: arg.parameterType.name,
};
}),
};
}),
};
});
}
function mapArgumentGroup(group) {
return {
start: group.start,
value: group.value,
children: (0, value_checker_1.doesHaveValue)(group.children)
? group.children.map((child) => mapArgumentGroup(child))
: undefined,
};
}
//# sourceMappingURL=assemble_test_cases.js.map
;