typescriptcucumbercypress

Cypress cucumber preprocessor custom parameter type with typescript


I am using cypress-cucumber-preprocessor with cypress and typescript. Also I noticed there is a possibility to use custom parameter types as shown here: https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/blob/master/cypress/support/step_definitions/customParameterTypes.js

But I am getting trouble running it with Typescript.

Interface in typscript is defined as export function defineParameterType(): void; so if I import module, I cannot write a propper definition.

But if I use javascript as shown in expamle, then I always get error

Uncaught Error: Undefined parameter type {boolean}

My javascript code looks like this:

defineParameterType({
  name: "boolean",
  regexp: /true|false/,
  transformer(s) {
    return s === 'true';
  }
});

Is there a way to get it working using Typescript?


Solution

  • The documentation around the custom types is a little light (this isn't a criticism of the package authors btw, documentation is hard work).

    I was able to make it work by defining my custom types in support/custom-parameter-types.ts and then in step files where I wanted to use custom types imported that file using import '<path-to-your-support-folder>/custom-parameter-types';

    I'm not 100% sure this is exactly the right way to do things, but it does seem to work.

    Edit: I should note that while this works, depending on your editor/IDE you might find that steps appear undefined in your feature files.