cucumber-js-tsflow
cucumber-js-tsflow copied to clipboard
PR #34 dropped support for cucumber-js-tsflow custom snippet syntax
As we can see now, the binding-decorator.ts
in master
has this block of commented code:
https://github.com/timjroberts/cucumber-js-tsflow/blob/master/cucumber-tsflow/src/binding-decorator.ts#L109-L125
// Decorate the Cucumber step definition snippet builder so that it uses our syntax
// let currentSnippetBuilder = cucumberSys.SupportCode.StepDefinitionSnippetBuilder;
// cucumberSys.SupportCode.StepDefinitionSnippetBuilder = function (step, syntax) {
// return currentSnippetBuilder(step, {
// build: function (functionName: string, pattern, parameters, comment) {
// let callbackName = parameters[parameters.length - 1];
// return `@${functionName.toLowerCase()}(${pattern})\n` +
// `public ${functionName}XXX (${parameters.join(", ")}): void {\n` +
// ` // ${comment}\n` +
// ` ${callbackName}.pending();\n` +
// `}\n`;
// }
// });
// }
I believe this PR #34 is where the built-in snippet decorator was commented out: https://github.com/timjroberts/cucumber-js-tsflow/pull/34/commits/d159a47f224a21e1253b05f0f48d8d17a9f9df10#diff-44991f7198d02f3c51a1f2243605a869b7344190138f6e06db644d0f9a4e406bL95-L109
I am creating this because what I get now from non-implemented snippets is barebone Cucumber methods like this:
Given('{personas} are employed by {string}', async function (personas, string) {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
The interface was changed in cucumber, so I had fixed the implementation locally as a separate file, based on official example
(https://github.com/cucumber/cucumber-js/blob/main/features/step_definition_snippets_custom_syntax.feature#L15-L44), cucumber-snippets-tsflow
npm package and original implementation in this repo
cucumber-missing-steps.js
:
function TsFlow(snippetInterface) {
return {
build: function build(opts) {
var implementation, async, returnType;
if (snippetInterface === 'callback') {
implementation = "callback(null, 'pending');";
returnType = 'void';
} else if (snippetInterface === 'async-await') {
implementation = "return 'pending';";
async = 'async';
returnType = 'Promise<void>';
} else {
implementation = "return 'pending';";
returnType = 'void';
}
var definitionChoices = opts.generatedExpressions.map(
function (generatedExpression, index) {
var prefix = index === 0 ? ' ' : '//';
var allParameterNames = generatedExpression.parameterNames.concat(opts.stepParameterNames);
if (snippetInterface === 'callback') {
allParameterNames.push('callback');
}
var parametersStr = '('
+ (allParameterNames.length === 0 ? '' : '\n' + prefix + ' ')
+ allParameterNames.join(', ') + '): ' + returnType;
var expression = generatedExpression.source.replace(/'/g, '\\\'');
var methodName = expression
.replace(/{/g, ' ') // change all brackets to spaces
.replace(/}/g, ' ') // change all brackets to spaces
.replace(/,/g, ' ') // change all commas to spaces
.replace(/\s([^\s])/g, function ($1) { // uppercase each word first letter
return $1.toUpperCase();
})
.replace(/\s/g, '') // remove all spaces
.replace(/[^\w]/g, '') // remove all things that are not a word
.replace(/^(.)/, function ($1) { // make first sentence letter lowercase
return $1.toLowerCase();
});
return `${prefix}@${opts.functionName.toLowerCase()}("${expression}")\n`
+ `${prefix}public ${async} ${methodName}${parametersStr} {\n`
}
)
return `${definitionChoices.join('')}`
+ ` // ${opts.comment}\n`
+ ` ${implementation}\n`
+ ` }`;
}
};
}
module.exports = TsFlow;
this is my cucumber.js
profile file:
const common = {
paths: [
'src/features/**/*.feature'
],
publishQuiet: true,
publish: false,
requireModule: ['ts-node/register'],
require: [
'src/step-definitions/**/*.ts'
],
}
module.exports = {
missingSteps: {
...common,
format: ["snippets"],
formatOptions: {
snippetInterface: "async-await",
snippetSyntax: "./cucumber-missing-steps.js"
},
dryRun: true
}
}
package.json
:
{
"scripts": {
"test:gherkin-missing-steps": "cucumber-js --profile missingSteps"
}
}
sample snippet generated:
@when("worker {int} fetches {taskType} task")
public async workerIntFetchesTaskTypeTask(
int, taskType): Promise<void> {
//@when("worker {float} fetches {taskType} task")
//public async workerFloatFetchesTaskTypeTask(
// float, taskType): Promise<void> {
// Write code here that turns the phrase above into concrete actions
return 'pending';
}
@then("last task fetch should have null result")
public async lastTaskFetchShouldHaveNullResult(): Promise<void> {
// Write code here that turns the phrase above into concrete actions
return 'pending';
}
@given("{personas} are employed by {string}")
public async personasAreEmployedByString(
personas, string): Promise<void> {
// Write code here that turns the phrase above into concrete actions
return 'pending';
}
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.
There hasn't been any activity on this issue for 67 days. Closing it as Spoiled.