testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

Unable to run the tests in ESM

Open vasyas opened this issue 1 year ago • 1 comments

What is your Scenario?

Unable to run the simplest tests when adding type: "module" to package.json

What is the Current behavior?

After launching testcafe I'm getting the error:

~/projects/github/testcafe-esm-bug> testcafe chrome test.mjs --esm
ERROR Cannot prepare tests due to the following error:

ReferenceError: require is not defined in ES module scope, you can use import instead
    at file:///Users/vasyas/projects/github/testcafe-esm-bug/test.mjs:1:27

Type "testcafe -h" for help.

What is the Expected behavior?

The test should be launched

What is the public URL of the test page? (attach your complete example)

http://example.com

What is your TestCafe test code?

import { Selector } from 'testcafe';

fixture `Fixture`
    .page('http://example.com');

test('test', async t => {
  await t
      .click('body')
      .expect(Selector('h1').text).eql('Example Domain');
});

Your complete configuration file

Not overridden

Your complete test report

No response

Screenshots

image

Steps to Reproduce

  1. Checkout repo https://github.com/vasyas/testcafe-esm-bug
  2. Run npm install
  3. Run npm run web to launch testcafe
  4. Observe error

TestCafe version

3.5.0

Node.js version

v20.11.0

Command-line arguments

testcafe chrome test.mjs --esm

Browser name(s) and version(s)

Chrome

Platform(s) and version(s)

MacOS

Other

Testcafe is the only dependency in the project.

Git repo with reproduction https://github.com/vasyas/testcafe-esm-bug

vasyas avatar Jan 27 '24 23:01 vasyas

We appreciate you taking the time to share information about this issue. We reproduced the bug and added this ticket to our internal task queue. We'll update this thread once we have news.

github-actions[bot] avatar Feb 01 '24 07:02 github-actions[bot]