Running tests with mocking extension fails to package successfully, both in debug and release mode. Metro complains about a certain module imported from the Detox logger (unable to resolve module path). When building and starting the packager without the extension environment variable, tests work properly but obviously use the non-mock files.
Provide the steps necessary to reproduce the issue. If you are seeing a regression, try to provide the last known version where the issue did not reproduce.
detox builddetox testTests should run and use files with the proper extension, as intended.

.detoxrc.json
{
"testRunner": "jest",
"runnerConfig": "src/e2e/config.json",
"configurations": {
"ios": {
"type": "ios.simulator",
"binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/appname.app",
"build": "RN_SRC_EXT=e2e.ts xcodebuild -workspace ios/Appname.xcworkspace -scheme Appname -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
"device": {
"type": "iPhone 11"
}
},
"android": {
"type": "android.emulator",
"binaryPath": "android/app/build/outputs/apk/detox/debug/app-detox-debug.apk",
"build": "cd android && RN_SRC_EXT=e2e.ts ./gradlew assembleDetoxDebug assembleDetoxDebugAndroidTest -DtestBuildType=debug && cd ..",
"device": {
"avdName": "Nexus_6P_API_29"
}
}
}
}
config.json
{
"testEnvironment": "./environment",
"testRunner": "jest-circus/runner",
"testTimeout": 120000,
"testRegex": "\\.e2e\\.(js$||ts$)",
"reporters": ["detox/runners/jest/streamlineReporter"],
"verbose": true
}
environment.js
const {
DetoxCircusEnvironment,
SpecReporter,
WorkerAssignReporter
} = require("detox/runners/jest-circus");
class CustomDetoxEnvironment extends DetoxCircusEnvironment {
constructor(config) {
super(config);
// 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;
@noomorph Any ideas? Thanks
I would also like to add that I've really narrowed it down to the mocking issue, since I've tried running both the build and bundler with the extension environment variable set while not importing any file that had a mocked counterpart. In this scenario the bundle is able to be built without any errors.
I'll run the described steps soon and check if I am able to reproduce:
- Create new RN application
- Setup Detox
- Setup mocking, as explained in docs/Guide.Mocking.md
- Build the app via detox build
- Run tests via detox test
Something doesn't make sense, are you trying to load Detox logger into your app? Detox code is meant to run in node under your test runner, not in your app's code.
Can you verify please?
@rotemmiz Nope, I even tried disabling the logger via the command line argument. I just checked and I only import expect, element, by and device from Detox. As I said previously, the same setup works when removing the custom extension environment variable from build and packager commands.
Still, this is what the error from the packager says, make sure you don't import detox code into your project (in that case, don't import detox code into your mocks).
I can try without importing the things I mentioned in my previous comment, those were mostly to get accurate TypeScript checking (otherwise the jest globals would take precedence).
I've tried removing all detox imports for element, expect, by, etc. and tried rebuilding + packaging with the mock extension environment variable. This resulted in a successful build (no change there) and a different error when packaging, now Metro complains about not being able to resolve one of my own files, which is a located in the e2e folder and contains test credentials and such.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back.
Thank you for your contributions!
For more information on bots in this reporsitory, read this discussion.