Cucumber-js: ya no puedo omitir un escenario en v7

Creado en 1 ene. 2021  ·  3Comentarios  ·  Fuente: cucumber/cucumber-js

En V6, para omitir un escenario, utilicé un gancho Antes de cada escenario

Before({ tags: '<strong i="6">@ignore</strong>' }, async function () {
  return 'skipped';
});

Este mismo código ya no se compila en v7 con mecanografiado:

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>'.

¿Cuál es la forma correcta de omitir un escenario en la v7?

Gracias

bug since-7

Comentario más útil

Me encontré con exactamente el mismo problema al agregar soporte para Cucumber v7 a Serenity / JS .

Me parece que es un problema con las definiciones de tipos en lugar de la funcionalidad real, que funciona exactamente de la misma manera que solía hacerlo en v6.

@charlierudolph / @davidjgoss , ¿le importaría comprobar si mi pensamiento a continuación es correcto?

En support_code_library_builder/types.ts hay las siguientes definiciones:

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

Dado que Cucumber permite que el gancho devuelva void , un string de 'skipped' o 'pending' , o un Promise con uno de esos resultados , una implementación mejorada podría verse más o menos así:

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

Hasta que se introduzca este o un cambio similar, una solución para este problema sería especificar el gancho de prueba de la siguiente manera:

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

Before({ tags: '<strong i="25">@ignore</strong>' }, function () {
    return 'skipped' as any;
});

Todos 3 comentarios

Me encontré con exactamente el mismo problema al agregar soporte para Cucumber v7 a Serenity / JS .

Me parece que es un problema con las definiciones de tipos en lugar de la funcionalidad real, que funciona exactamente de la misma manera que solía hacerlo en v6.

@charlierudolph / @davidjgoss , ¿le importaría comprobar si mi pensamiento a continuación es correcto?

En support_code_library_builder/types.ts hay las siguientes definiciones:

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

Dado que Cucumber permite que el gancho devuelva void , un string de 'skipped' o 'pending' , o un Promise con uno de esos resultados , una implementación mejorada podría verse más o menos así:

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

Hasta que se introduzca este o un cambio similar, una solución para este problema sería especificar el gancho de prueba de la siguiente manera:

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

Before({ tags: '<strong i="25">@ignore</strong>' }, function () {
    return 'skipped' as any;
});

Hola @ jan-molak, muchas gracias por tus comentarios, ¡tu solución funciona perfectamente!

Gracias por la solución @ jan-molak. Echaré un vistazo a esta en breve.

¿Fue útil esta página
0 / 5 - 0 calificaciones