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

Cucumber fails to run Typescript steps with Angular dependencies

Open AdamAntinoo opened this issue 1 year ago • 2 comments

👓 What did you see?

After a fresh installation of Cucumber with @cucumber/[email protected] over an [email protected] project the cucumber steps start to fail with error

import { Given } from "@cucumber/cucumber";
^^^^^^
SyntaxError: Cannot use import statement outside a module

This exception starts to fail not at the first coding iteration but when the steps start to have dependencies to use dependency injections.

✅ What did you expect to see?

The complete runs of the defined cucumber steps

📦 Which tool/library version are you using?

Angular 17.2.0 Cucumber 10.3.1 ts-node 10.9.2 node v20.11.1 npm 10.2.4

🔬 How could we reproduce it?

  • Install angular 17.2.0 with -> npm -g install @angular/[email protected]
  • Create a new project -> ng new cucumber-test
  • Install additional modules
cd cucumber-test
npm install --save-dev @cucumber/cucumber ts-node
  • Edit the project package.json and add a new script to run cucumber.
"cucumber": "./node_modules/@cucumber/cucumber/bin/cucumber-js ./cucumber/**/*.feature --no-strict --require-module ts-node/register --require ./cucumber/**/*.step.ts --tags @NIF05.01"
  • Create a new feature with tag @NIF05.01->cucumber/features/NIF05.feature
@NIF05 @DashboardHome
Feature: [NIF05]-Fetch data

  @NIF05 @NIF05.01
  Scenario: [NIF05.01]-Get the initial set of data.
      | uniqueId | accountId |
      | 93813310 | 93813310  |
    When the ESI endpoint "Get Mining Data" is called
    Then the result is "200 OK"
  • Run cucumber to get the steps for the new feature steps.
  • Create the step file->cucumber/steps/NIF05.step.ts with the generated stubs
import { Given, When, Then } from "@cucumber/cucumber"

When('the ESI endpoint {string} is called', function (string) {
  // Write code here that turns the phrase above into concrete actions
  return 'pending'
})
Then('the result is {string}', function (string) {
  // Write code here that turns the phrase above into concrete actions
  return 'pending'
})

📚 Any additional context?

The example executions have been done after following instructions for Typescript found at page https://github.com/cucumber/cucumber-js/blob/main/docs/transpiling.md

AdamAntinoo avatar Mar 12 '24 09:03 AdamAntinoo

What is your tsconfig for this project?

davidjgoss avatar Mar 12 '24 10:03 davidjgoss

I'm going to move this issue to our examples repo and see if we can add a minimal working example of Angular+Cucumber over there.

davidjgoss avatar Apr 27 '24 07:04 davidjgoss