Cucumber-js: cannot skip a scenario anymore in v7

Created on 1 Jan 2021  路  3Comments  路  Source: cucumber/cucumber-js

In V6, to skip a scenario, I used a Before each scenario hook

Before({ tags: '@ignore' }, async function () {
  return 'skipped';
});

This same code does not compile anymore in v7 with typescript:

error TS2769: No overload matches this call.
  Overload 1 of 3, '(tags: string, code: TestCaseHookFunction): void', gave the following error.
    Argument of type '{ tags: string; }' is not assignable to parameter of type 'string'.
  Overload 2 of 3, '(options: IDefineTestCaseHookOptions, code: TestCaseHookFunction): void', gave the following error.
    Argument of type '(this: CustomWorld) => Promise<string>' is not assignable to parameter of type 'TestCaseHookFunction'.
      Type '(this: CustomWorld) => Promise<string>' is not assignable to type 'TestCaseHookFunctionWithoutParameter'.
        Type 'Promise<string>' is not assignable to type 'void | Promise<void>'.
          Type 'Promise<string>' is not assignable to type 'Promise<void>'.

What is the right way to skip a scenario in v7?

Thanks

bug since-7

Most helpful comment

I just came across the exact same issue while adding support for Cucumber v7 to Serenity/JS.

It seems to me that it's a problem with type definitions rather than the actual functionality, which works the exact same way as it used to in v6.

@charlierudolph / @davidjgoss, would you mind checking if my thinking below is correct?

In support_code_library_builder/types.ts there are following definitions:

export type TestCaseHookFunctionWithoutParameter = () => void | Promise<void>
export type TestCaseHookFunctionWithParameter = (
  arg: ITestCaseHookParameter
) => void | Promise<void>

Since Cucumber allows for the hook to return void, a string of 'skipped' or 'pending', or a Promise with one of those results, an improved implementation could look more or less like this:

export type TestCaseHookFunctionResult = 'skipped' | 'pending' | void
export type TestCaseHookFunctionWithoutParameter = () => TestCaseHookFunctionResult | Promise<TestCaseHookFunctionResult>
export type TestCaseHookFunctionWithParameter = (
  arg: ITestCaseHookParameter
) => TestCaseHookFunctionResult | Promise<TestCaseHookFunctionResult>

Until this or similar change is introduced, a workaround for this issue would be specifying the test hook as follows:

import { Before } from '@cucumber/cucumber';

Before({ tags: '@ignore' }, function () {
    return 'skipped' as any;
});

All 3 comments

I just came across the exact same issue while adding support for Cucumber v7 to Serenity/JS.

It seems to me that it's a problem with type definitions rather than the actual functionality, which works the exact same way as it used to in v6.

@charlierudolph / @davidjgoss, would you mind checking if my thinking below is correct?

In support_code_library_builder/types.ts there are following definitions:

export type TestCaseHookFunctionWithoutParameter = () => void | Promise<void>
export type TestCaseHookFunctionWithParameter = (
  arg: ITestCaseHookParameter
) => void | Promise<void>

Since Cucumber allows for the hook to return void, a string of 'skipped' or 'pending', or a Promise with one of those results, an improved implementation could look more or less like this:

export type TestCaseHookFunctionResult = 'skipped' | 'pending' | void
export type TestCaseHookFunctionWithoutParameter = () => TestCaseHookFunctionResult | Promise<TestCaseHookFunctionResult>
export type TestCaseHookFunctionWithParameter = (
  arg: ITestCaseHookParameter
) => TestCaseHookFunctionResult | Promise<TestCaseHookFunctionResult>

Until this or similar change is introduced, a workaround for this issue would be specifying the test hook as follows:

import { Before } from '@cucumber/cucumber';

Before({ tags: '@ignore' }, function () {
    return 'skipped' as any;
});

Hi @jan-molak , thank you very much for your feedback, your workaround works perfectly !

Thanks for the workaround @jan-molak - I'll take a look at this one shortly.

Was this page helpful?
0 / 5 - 0 ratings