8

I have a simple project that is basically...

export class Application{
  constructor(...){
    ...
  }
  async run(){
    console.log("I Ran!");
  }
}

I want to run this using Cukes so I follow these steps and get this working (notice the .cjs extension to signify to node it is a cjs file)

// features/basic.feature

Feature: Hello World
  Scenario: Hello World
    Given I start the app
    When it is running
    Then I see the console

// features/support/steps.cjs
const { Given, When, Then } = require("@cucumber/cucumber");

Given("I start the app", function () {
  // TODO: Setup child process
  return
});

When("it is running", function () {
  // TODO: Execute using Worker
  return
});

Then("I see the console", function () {
  // assert.equal(this.variable, number);
  return
});

I would execute this using cucumber-js --require features/support/steps.cjs

But now I want to import Application and run the application in a step. Since I can't import a ESM (.mjs) file using .cjs I am not sure how to do this. I tried creating a .mjs version of the step file but I can't get that working either. I also tried cucumber-js --require-module features/support/steps.mjs but it still didn't work.

How do I use Cukes with an ESM-style project?

Jackie
  • 21,969
  • 32
  • 147
  • 289
  • As far as I know, this is still an issue. There is an experimental version of cukes to work with (7.2.0). However, version 8.0.0 is on it's way which has a lot of these issues addressed. The new release is due out in the next few days (fingers crossed). Here's the link for all the work they have done to date: [cucumber-js add ESM support (take 2)](https://github.com/cucumber/cucumber-js/pull/1649) – djmonki Oct 26 '21 at 12:41

1 Answers1

1

As far as I know, this is still an issue. There is an experimental version of cukes to work with, which started addressing these issues (cukes version 7.2.0), that you could start using to see if you can address the changes you want to implement.

However, version 8.0.0 is on it's way which has a lot of these issues addressed in particular. The new release is due out in the next few days (fingers crossed).

Here's the link for all the work they have done to date to address the issues you are experiencing: cucumber-js add ESM support (take 2)

djmonki
  • 3,020
  • 7
  • 18