gpt4 book ai didi

typescript - 用 RN Detox 模拟

转载 作者:行者123 更新时间:2023-12-04 13:55:57 27 4
gpt4 key购买 nike

我正在关注 detox mocking guide与 typescript 。该应用程序始终打印 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"
}
}
}
}

地铁配置文件
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 test Metro 服务器不记录 e2d 文件,所以我不得不使用 RN_SRC_EXT=e2e.js,e2e.ts yarn start 单独运行 Metro

最佳答案

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

关于typescript - 用 RN Detox 模拟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62342688/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com