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

Step undefined when we using api function

Open obouhlel opened this issue 1 year ago • 1 comments

👓 What did you see?

With this code:

import { runCucumber, loadConfiguration, loadSupport } from '@cucumber/cucumber/api'

async function run(name) {
	const { runConfiguration } = await loadConfiguration({ file: `./config/${name}.json` })

	const env = {
		cwd: process.cwd(),
		stdout: process.stdout,
		stderr: process.stderr,
		debug: false
	}
	
	const support = await loadSupport(runConfiguration, env)
	console.log(support)
  
	await runCucumber({ ...runConfiguration, support }, env, (message) => {
		(message)
	})
}

run("add").then(() => run("sub"))

The second time I run the scenario (or any subsequent runs), the steps are undefined. When I log the support variable using console.log, the stepDefinitions attribute is empty.

✅ What did you expect to see?

I expect the support variable to retain the stepDefinitions attribute.

📦 Which tool/library version are you using?

node: 18.20.4 cucumber: 11.0.1

🔬 How could we reproduce it?

In this repository, I have created a simple test to reproduce this issue.

  1. npm install
  2. npm run test

📚 Any additional context?

No response

obouhlel avatar Sep 26 '24 12:09 obouhlel

I expect the support variable to retain the stepDefinitions attribute.

Your support variable only exists in the scope of your run function though, so each invocation tries to create it afresh, but you're in the same overall Node.js process so it only works the first time.

Assuming your support code is consistent across your runs, then you should be able to call loadSupport just once upfront, before any of your calls to run, and pass in your support object each time.

davidjgoss avatar Sep 26 '24 15:09 davidjgoss