3

Using testcafe v1.17.0.

I have the configuration file .testcaferc.js with the newly merged global hooks property. In all of my fixtures, I have a before hook which does a certain amount of requests to an API, and with the new global hooks I wanted to move all of those API calls to the configuration file. (to remove duplicate code among other reasons)

However, it doesn't seem to be possible to import other files or packages into the configuration file as it throws the following error when I try to run testcafe:

An error has occurred while reading the "C:\Users\User\Documents\Projects\testcafe\.testcaferc.js" configuration file.

Not really sure what I need to do here to make this work.

There are two examples of what I need to import into the config file. Either one of them throws the aforementioned error.

import Shared from "./shared"; // Custom JS file containing functions for the API requests
import clonedeep from 'lodash.clonedeep';
Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
Adam Silva
  • 1,013
  • 18
  • 48

1 Answers1

4

The .testcaferc.js configuration file should be in the CommonJS format, so you should use require instead of import. Your imported modules should also be written in the cjs format.

Alex Kamaev
  • 6,198
  • 1
  • 14
  • 29
  • Thanks! That was it! I'm assuming there is no way to make it work with the ES6 format? I tried simply changing to `export default` and it didn't work – Adam Silva Nov 11 '21 at 10:59
  • TestCafe does not support ES modules in the configuration file. You can only process your configuration file (e.g., with babel) before the TestCafe is started. – Alex Kamaev Nov 12 '21 at 08:14