3
votes

Please can somebody tell me how the mock files for react native detox tests ? I following this article

I am using react-native version 0.57.7 and detox 9.1.2

I created rn-cli.config.js in root directory

const defaultSourceExts = require('metro-config/src/defaults/defaults').sourceExts
module.exports = {
  resolver: { 
    sourceExts: process.env.RN_SRC_EXT
                ? process.env.RN_SRC_EXT.split(',').concat(defaultSourceExts)
                : defaultSourceExts
  }
};

I created mock files right next to production files with e2e extension enter image description here

then i run Metro with command (i am using windows powershel 6)

$env:RN_SRC_EXT="e2e.ts";react-native start
react-native run-android

and NOTHING, literally nothing is changed/mocked

I also tried build and run detox

cd android;$env:ENVFILE="../config/default/env";gradle assembleDebug assembleAndroidTest -DtestBuildType=debug;cd ..
detox test -c android.emu.debug.win

but also nothing happend, i removed all node_modules, android build folder but no effect.

Did i miss something ?

1

1 Answers

2
votes

Your rn-cli.config.js file is correct, but try adding this in your detox e2e/config.json

"testMatch": ["**/__tests__/**/*.js?(x)", "**/?(*.)(e2e).js?(x)"]

Mine is something like this:

{
    "setupFilesAfterEnv": ["./init.js"],
    "testEnvironment": "node",
    "reporters": ["detox/runners/jest/streamlineReporter"],
    "testMatch": ["**/__tests__/**/*.js?(x)", "**/?(*.)(e2e).js?(x)"],
    "verbose": true
}

I'm using react-native version 0.59.8 and detox 12.10.2

As you are using typescript, then write

"testMatch": ["**/__tests__/**/*.ts?(x)", "**/?(*.)(e2e).ts?(x)"],

With ts extension