4

我正在使用打字稿遵循排毒模拟指南。X.ts该应用程序始终打印文件而不是文件的console.log X.e2e.ts

依赖版本。

react-native: 0.61.5,
detox: 16.4.0

地铁配置:

"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
};

当我运行detox build && detox testMetro 服务器时不会记录 e2d 文件,所以我必须使用单独运行 MetroRN_SRC_EXT=e2e.js,e2e.ts yarn start

4

1 回答 1

0

我也尝试过这种方法,但它比测试更多样板,检查一下:https ://www.npmjs.com/package/10mock你可以在这里查看示例代码:https ://github.com/10play/10mock-示例应用

于 2021-09-06T15:14:53.603 回答