testcafe
testcafe copied to clipboard
Unable to run the tests in ESM
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
Steps to Reproduce
- Checkout repo https://github.com/vasyas/testcafe-esm-bug
- Run
npm install - Run
npm run webto launch testcafe - 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
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.