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

Nightwatch force importing cucumber files in CJS even if Cucumber is configured to use ESM #3805

Closed
thermsdorff opened this issue Jul 12, 2023 · 3 comments · Fixed by #3806
Closed

Comments

@thermsdorff
Copy link
Contributor

thermsdorff commented Jul 12, 2023

Description of the bug/issue

When I try to run tests through native Cucumber runner, i expect nightwatch to import modules regarding cucumber's modules importation configuration (commonJS or ESM)

Context

All my source code is using ESM, Cucumber is configured to use ESM, nightwatch config is using CJS

  • Cucumber version : 9.2.0

Cucumber configuration

{
  paths: ['./src/config/features/**/*.feature'],
  import: [
    './src/step-code/app/index.js',
    './src/step-definitions/step_definitions.js',
    './src/config/hooks.js',
  ],
  format: ['@cucumber/pretty-formatter', 'json:/reports/run.json'],
  publishQuiet: true,
  forcExit: true,
}

Steps to reproduce

  1. Configure Cucumber to use ESM
  2. Run nightwatch test
  3. See error :
 Cucumber expected a CommonJS module at '/home/user/dev/project/src/step-definitions/step_definitions.js' but found an ES module.
Either change the file to CommonJS syntax or use the --import directive instead of --require.

Sample test

No response

Command to run

yarn nightwatch

Verbose Output

No response

Nightwatch Configuration

const defaultProfile = {
  selenium: {
    host: process.env.SELENIUM_HOST,
    port: 4444,
    start_process: false,
  },
};

const defaultCapabilities = [
  'disable-dev-shm-usage',
  'disable-setuid-sandbox',
  'disable-infobars',
  'enable-automation',
  'start-fullscreen',
  'allow-running-insecure-content',
  'disable-popup-blocking',
  'ignore-certificate-errors',
  'test-type',
  'lang=fr',
  'disable-gpu',
  'privileged',
  'app=https://myapp.com',
  'window-size=1920,1080',
];

const chromeProfile = {
  ...defaultProfile,
  desiredCapabilities: {
    browserName: 'chrome',
    javascriptEnabled: true,
    acceptSslCerts: true,
    chromeOptions: {
      w3c: true,
      args: [...defaultCapabilities],
    },
  },
};

module.exports = {
  src_folders: ['./src/step-definitions/step_definitions.js', './src/config/hooks.js'],
  output_folder: false,
  page_objects_path: './src/pages/app',
  launch_url: 'https://myapp.com',
  disable_colors: false,
  silent: true,
  detailed_output: false,
  enable_fail_fast: true,
  disable_error_log: true,
  globals: {
    waitForConditionTimeout: 5000,
  },
  test_runner: {
    type: 'cucumber',
    options: {
      feature_path: 'src/config/feature/**/*.feature',
      auto_start_session: true,
      parallel: 1,
    },
  },
  test_settings: {
    default: chromeProfile,
  },
};

Nightwatch.js Version

3.0.1

Node Version

18.16.0

Browser

No response

Operating System

No response

Additional Information

No response

@thermsdorff
Copy link
Contributor Author

This method from https://github.com/nightwatchjs/nightwatch/blob/e7fde68bdf6dd43e9a1c7bcd38263f54dd287bda/lib/runner/test-runners/cucumber.js#L109C1-L109C1

createInitialRequires() {
    const initialRequires = [
      '--require', CucumberSuite.cucumberSetupFile
    ];

    initialRequires.push(...this.buildArgvValue(['require', 'require-module']));

    return this.allModulePaths.reduce((prev, spec) => {
      prev.push('--require', spec);

      return prev;
    }, initialRequires);
  }

should use --import in case of cucumber use ESM.

@thermsdorff
Copy link
Contributor Author

Current workaround is using programmatical API but this prevents the use of new nightwatch inspector feature and other stuff coming from nightwatch runners :(

@Maxooo
Copy link

Maxooo commented Jul 12, 2023

Same issue here !

thermsdorff added a commit to thermsdorff/nightwatch that referenced this issue Jul 12, 2023
AutomatedTester pushed a commit that referenced this issue Jul 18, 2023
* fix(cucumber-runner): allow esm imports (#3805)

* fix(cucumber-runner): add cli-arg 'enable-esm'

* test(cucumber-runner): add tests for enable esm options/cli arg
yashPratp983 pushed a commit to yashPratp983/nightwatch that referenced this issue Jul 25, 2023
…chjs#3806)

* fix(cucumber-runner): allow esm imports (nightwatchjs#3805)

* fix(cucumber-runner): add cli-arg 'enable-esm'

* test(cucumber-runner): add tests for enable esm options/cli arg
yashPratp983 pushed a commit to yashPratp983/nightwatch that referenced this issue Jul 25, 2023
…chjs#3806)

* fix(cucumber-runner): allow esm imports (nightwatchjs#3805)

* fix(cucumber-runner): add cli-arg 'enable-esm'

* test(cucumber-runner): add tests for enable esm options/cli arg
yashPratp983 pushed a commit to yashPratp983/nightwatch that referenced this issue Jul 25, 2023
…chjs#3806)

* fix(cucumber-runner): allow esm imports (nightwatchjs#3805)

* fix(cucumber-runner): add cli-arg 'enable-esm'

* test(cucumber-runner): add tests for enable esm options/cli arg
yashPratp983 pushed a commit to yashPratp983/nightwatch that referenced this issue Jul 25, 2023
…chjs#3806)

* fix(cucumber-runner): allow esm imports (nightwatchjs#3805)

* fix(cucumber-runner): add cli-arg 'enable-esm'

* test(cucumber-runner): add tests for enable esm options/cli arg
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

Successfully merging a pull request may close this issue.

2 participants