Currently, I am referring to the Detox mocking guide specifically with typescript. The issue I am facing is that the app consistently logs console.log from the X.ts
file instead of the expected X.e2e.ts
file.
Here are the versions of dependencies in use:
react-native: 0.61.5,
detox: 16.4.0
Metro Configuration:
"detox": {
"test-runner": "jest",
"runner-config": "e2e/config.json",
"configurations": {
"ios.sim.debug": {
"binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/App.app",
"build": "RN_SRC_EXT=e2e.js,e2e.ts xcodebuild -workspace ios/App.xcworkspace -scheme 'App Test' -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
"type": "ios.simulator",
"device": {
"type": "iPhone 11"
}
}
}
}
metro.config.js
const defaultSourceExts = require("metro-config/src/defaults/defaults").sourceExts;
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false
}
})
},
resolver: {
sourceExts: process.env.RN_SRC_EXT ? process.env.RN_SRC_EXT.split(",").concat(defaultSourceExts) : defaultSourceExts
}
};
console.log("default", defaultSourceExts);
console.log("module.exports from e2e", module.exports);
/** above console results into the following
default [ 'js', 'json', 'ts', 'tsx' ]
module.exports from e2e { transformer:
{ getTransformOptions: [AsyncFunction: getTransformOptions] },
resolver: { sourceExts: [ 'e2e.ts', 'js', 'json', 'ts', 'tsx' ] } }
*/
/src/AppEvent.js
const logEvent = (): void => {
console.log("from non-test event file");
};
export default {
logEvent
};
/src/AppEvent.e2e.ts
const logEvent = (): void => {
console.log("from test event file");
};
export default {
logEvent
};
When executing
detox build && detox test
, the metro server fails to log e2d files. To address this, I had to individually run the metro server using RN_SRC_EXT=e2e.js,e2e.ts yarn start