cucumber-js icon indicating copy to clipboard operation
cucumber-js copied to clipboard

Steps are listed as undefined when running in parallel using Javascript API

Open uzeyirqa opened this issue 3 years ago • 3 comments

👓 What did you see?

Cucumber Lists step definitions as undefined when running in parallel using the Javascript API functions. I needed to pass the support code from 1 repo to another so I made the first repo a package and use the JS API functions to pass the support code.

this is how I run the tests:

async function runTests() {

  const environment = { cwd: process.cwd() };

  const { runConfiguration } = await loadConfiguration({
    file: configFilePath,
    provided: {
      failFast: false,
      backtrace: false,
      parallel:createProfile().parallel,
      tags:config.tags,
      paths:getFeatures(),
      require: [path.resolve(__dirname, 'support'), getStepsPath()],
      format: [`json:${path.resolve(__dirname, 'cucumber-report.json')}`]},
      profile: program.profile||'default',
  },environment);

 const success =  await runCucumber(runConfiguration, environment);
  return success;
}
runTests();

The tests are being executed but i get all the scenarios listed as undefined in the console before the tests start. although all scenarios are implemented.

✅ What did you expect to see?

Expect that scenarios will run without listing their steps as undefined.

📦 Which tool/library version are you using?

@Cucumber/cucumber: 8.5.1 Node version: 14.20.0 Os: MacOs Monterey 12.5.1

uzeyirqa avatar Aug 21 '22 12:08 uzeyirqa

Are you able to make a minimal reproducible example repo for this?

Looking at how you’re using the API there, it seems like you just need to dynamically build the configuration - you should be able to achieve what you want just by writing your configuration file in JavaScript. Does this change anything for you?

davidjgoss avatar Aug 21 '22 13:08 davidjgoss

Thank you, I will try to create a repo to reproduce during the week. Regarding dynamically building the configuration file I actually do that by having a profiles file:

const common = {
    steps: './steps',
    featureFiles: './features',
    reports: './reports',
    timeout: 120000,
};
module.exports = {
    default: {
        parallel: 2,
        worldParameters: {
            baseURL:xxxx
            accounts:xxx
            browser: process.env.BROWSER || 'chromium',
            headless: process.env.headless || false,
        },
    },
    my-second-env: {
        worldParameters: {
            baseURL:xxxx,
            accounts:xxxx,
            browser: process.env.BROWSER || 'chromium',
            headless: process.env.headless || false,
        },
    },
    common,
};

Then I read the profile which i want to run being passed from the CLI via this function in the index.js file of the package:

const profileFileName = path.resolve('profiles.js');

function createProfile() {
  if (fs.existsSync(profileFileName)) {
    if (program.profile) {
      const profileToCall = { ...require(profileFileName)[program.profile] };
      return profileToCall;
    }
    const defaultProfile = { ...require(profileFileName).default };
    return defaultProfile;
  }
}

And call the createProfile function in the cucumber.js file:

const createProfile = require('MY-PACKAGE').createProfile;
module.exports = {
    default: createProfile(),
};

I don't know if it's what you meant by dynamically creating it but it works. The only problem are the step definitions which are listed during parallel test run as undefined. It seems as though at first cucumber doesn't recognize the path to the support code.

uzeyirqa avatar Aug 21 '22 13:08 uzeyirqa

It's going to be hard to diagnose this on our side without an example repo we can check out and try.

But you might try upgrading to 8.6.0 and prepending DEBUG=cucumber to your command (or add debug: true to the environment object if using the API), so you get some logging to stderr around configuration etc - this might show up the issue. https://github.com/cucumber/cucumber-js/blob/main/docs/debugging.md

davidjgoss avatar Sep 20 '22 15:09 davidjgoss

Closing as this has gone quiet but please re-raise if you have additional details.

davidjgoss avatar Nov 24 '22 17:11 davidjgoss