timjroberts / cucumber-js-tsflow

Provides 'specflow' like bindings for Cucumber.js in TypeScript 1.7+.
MIT License
133 stars 34 forks source link

Step-Specific Timeout #72

Closed OhadR closed 4 years ago

OhadR commented 4 years ago

Hi,

maybe I miss something, but does this (great) package supports timeouts in a step level? I use the code below to set the "global" timeout, i.e. for ALL steps:

var {setDefaultTimeout} = require('cucumber');
setDefaultTimeout(10 * 1000); 

So far so good, but now I have a single step which take a lot of time so I want to allow specifically only this step to run 5 minutes without getting timeout error.

How can I achieve that?

currently I see no choice but to use "plain" cucumber again:


import { When } from "cucumber";

function sleep(seconds) {
    return new Promise(resolve => setTimeout(resolve, seconds * 1000));
}

When('wait {int} minutes', {timeout: 60 * 1000}, async function(numMinutes: number) {
    await sleep(numMinutes * 60);
});

is there a more elegant way, using tsflow?

(related to #29 )

wudong commented 4 years ago

Hi OhadR, the step specific timeout can actually be set now, for when/then/given, but not for the before/after hookd.

@given(/^some step to be executed$/, undefined, 1000) 
public someGiven(){
}

here, we set the timeout to be 1000ms. note the undefined before the timeout argument; it is for tag.

can you verify this works for u? if not i have have further check.

wudong commented 4 years ago

Added support for timeout in before/after hooks now.

OhadR commented 4 years ago

superb! thanks @wudong

tried to check it now. working perfectly.

I would add it also to the docs :-)

adomened commented 2 years ago

How can I add a 'timeout' to the 'before/after hooks'?

Can you give me an example, the documentation does not provide one. Thank you.

Do I need a specific version ?

I have set a default timeout until I have a more elegant solution. Just in case it helps:


// test-setup.js
require('ts-node').register({ 
    transpileOnly : true , 
    compilerOptions : { 
      "module" : "commonjs" , 
      "resolveJsonModule" : true , 
    }, 
});

require('@cucumber/cucumber').setDefaultTimeout(30 * 1000);

// cucumber.js
let common = [
    '--require tests.setup.js',             // Config ts-node
    'features/**/*.feature',                // Specify our feature files
    '--require-module ts-node/register',    // Load TypeScript module
    '--require step-definitions/**/*.ts',   // Load step definitions
    '--format progress-bar',                // Load custom formatter
  ].join(' ');

  module.exports = {
    siglo: common
  };