react-nativejestjsexpodetox

Detox/Jest Test suite failed to run TypeError: Class extends value #<Object> is not a constructor or null


I'm trying to integrate some e2e tests into my react native (expo ejected) mobile project. I'm following the instructions found on the detox Getting Started page. I'm able to successfully build my project, but everytime I attempt the detox test command:

detox test --configuration ios --loglevel trace

I get the following error:

FAIL  e2e/firstTest.e2e.jsrun...
  ● Test suite failed to run

    TypeError: Class extends value #<Object> is not a constructor or null

      at Object.<anonymous> (../node_modules/detox/runners/jest-circus/environment.js:24:38)
      at Object.newLoader (../node_modules/pirates/lib/index.js:141:7)
      at Object.<anonymous> (../node_modules/detox/runners/jest-circus/index.js:4:32)

09:07:59.324 detox[21032] ERROR: [cli.js] Command failed: jest --config e2e/config.json --testNamePattern '^((?!:android:).)*$' e2e

I have a fairly simple out-of-the-box configuration of detox and jest:

package.json

...
"detox": "^19.6.2"
"jest": "^27.0.0",
"jest-circus": "^27.5.1",
...

./e2e/config.json

{
  "testEnvironment": "./environment",
  "testRunner": "jest-circus/runner",
  "testTimeout": 120000,
  "testRegex": "\\.e2e\\.js$",
  "reporters": ["detox/runners/jest/streamlineReporter"],
  "verbose": true
}

./e2e/environment.js

const {
  DetoxCircusEnvironment,
  SpecReporter,
  WorkerAssignReporter,
} = require('detox/runners/jest-circus');

class CustomDetoxEnvironment extends DetoxCircusEnvironment {
  constructor(config, context) {
    super(config, context);

    // Can be safely removed, if you are content with the default value (=300000ms)
    this.initTimeout = 300000;

    // This takes care of generating status logs on a per-spec basis. By default, Jest only reports at file-level.
    // This is strictly optional.
    this.registerListeners({
      SpecReporter,
      WorkerAssignReporter,
    });
  }
}

module.exports = CustomDetoxEnvironment;

.detoxrc.json

{
  "testRunner": "jest",
  "runnerConfig": "e2e/config.json",
  "skipLegacyWorkersInjection": true,
  "apps": {
    "ios": {
      "type": "ios.app",
      "binaryPath": "ios/build/Build/Products/Release-iphonesimulator/Example.app",
      "build": "xcodebuild -workspace ios/Example.xcworkspace -configuration release -scheme Example -sdk iphonesimulator -derivedDataPath ios/build"
    },
    "android": {
      "type": "android.apk",
      "binaryPath": "SPECIFY_PATH_TO_YOUR_APP_BINARY"
    }
  },
  "devices": {
    "simulator": {
      "type": "ios.simulator",
      "device": {
        "type": "iPhone 12 Pro"
      }
    },
    "emulator": {
      "type": "android.emulator",
      "device": {
        "avdName": "Pixel_3a_API_30_x86"
      }
    }
  },
  "configurations": {
    "ios": {
      "device": "simulator",
      "app": "ios"
    },
    "android": {
      "device": "emulator",
      "app": "android"
    }
  }
}

It can't be this hard. Any help would be greatly appreciated.


Solution

  • Able to solve using Jest 27.0.1

    I asked on github because I had the same problem as you and they gave me this solution