Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cucumber fails to run Typescript steps with Angular dependencies #20

Open
AdamAntinoo opened this issue Mar 12, 2024 · 2 comments
Open
Assignees

Comments

@AdamAntinoo
Copy link

AdamAntinoo commented Mar 12, 2024

👓 What did you see?

After a fresh installation of Cucumber with @cucumber/cucumber@10.3.1 over an Angular@17.2.0 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/cli@17.2.0
  • 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

@davidjgoss
Copy link
Contributor

What is your tsconfig for this project?

@davidjgoss
Copy link
Contributor

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 davidjgoss transferred this issue from cucumber/cucumber-js Apr 27, 2024
@davidjgoss davidjgoss self-assigned this Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants