react-native - 使用 React-Navigation 时排毒测试挂起

标签 react-native react-navigation detox

我在我的 RN 应用程序中使用 react-navigation 进行导航。问题是当我运行 detox 时,测试只是挂起,但如果我删除导航并只渲染一个 React 组件,那么测试运行良好。以下是遵循本指南( https://github.com/wix/Detox/blob/master/docs/Guide.DebuggingInXcode.md )后的日志(使用 react-navigation 时):

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  * frame #0: 0x00007fff23bd5a3a CoreFoundation`_CFRelease + 186
    frame #1: 0x00007fff23bce337 CoreFoundation`__CFRunLoopDoObservers + 487
    frame #2: 0x00007fff23bce97a CoreFoundation`__CFRunLoopRun + 1514
    frame #3: 0x00007fff23bce066 CoreFoundation`CFRunLoopRunSpecific + 438
    frame #4: 0x000000010207ba6a EarlGrey`-[GREYRunLoopSpinner grey_drainRunLoopInActiveModeAndCheckCondition:forTime:](self=0x0000600002a524f0, _cmd="grey_drainRunLoopInActiveModeAndCheckCondition:forTime:", stopConditionBlock=0x00000001020c9560, time=1.7976931348623157E+308) at GREYRunLoopSpinner.m:175:31
    frame #5: 0x000000010207b435 EarlGrey`-[GREYRunLoopSpinner spinWithStopConditionBlock:](self=0x0000600002a524f0, _cmd="spinWithStopConditionBlock:", stopConditionBlock=0x00000001020c9560) at GREYRunLoopSpinner.m:58:26
    frame #6: 0x00000001020c8cba EarlGrey`-[GREYUIThreadExecutor executeSyncWithTimeout:block:error:](self=0x000060000252c300, _cmd="executeSyncWithTimeout:block:error:", seconds=1.7976931348623157E+308, execBlock=0x000000010209aec0, error=0x00007ffeef3274d0) at GREYUIThreadExecutor.m:227:22
    frame #7: 0x000000010209a3d1 EarlGrey`-[GREYElementInteraction assert:error:](self=0x0000600003b10a00, _cmd="assert:error:", assertion=0x00006000025db840, errorOrNil=0x0000000000000000) at GREYElementInteraction.m:436:9
    frame #8: 0x000000010209bd4d EarlGrey`-[GREYElementInteraction assertWithMatcher:error:](self=0x0000600003b10a00, _cmd="assertWithMatcher:error:", matcher=0x00006000025db820, errorOrNil=0x0000000000000000) at GREYElementInteraction.m:481:10
    frame #9: 0x000000010209bc7e EarlGrey`-[GREYElementInteraction assertWithMatcher:](self=0x0000600003b10a00, _cmd="assertWithMatcher:", matcher=0x00006000025db820) at GREYElementInteraction.m:476:10
    frame #10: 0x00007fff23c7820c CoreFoundation`__invoking___ + 140
    frame #11: 0x00007fff23c753af CoreFoundation`-[NSInvocation invoke] + 319
    frame #12: 0x0000000101f1833f Detox`+[DTXMethodInvocation invoke:onError:](self=DTXMethodInvocation, _cmd="invoke:onError:", params=3 key/value pairs, onError=0x0000000101f10f60) at DTXMethodInvocation.m:246:2
    frame #13: 0x0000000101f10bcc Detox`__35-[TestRunner invoke:withMessageId:]_block_invoke(.block_descriptor=0x0000600003b10ec0) at TestRunner.m:71:12
    frame #14: 0x00007fff23bd429c CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    frame #15: 0x00007fff23bd3a08 CoreFoundation`__CFRunLoopDoBlocks + 312
    frame #16: 0x00007fff23bcee1b CoreFoundation`__CFRunLoopRun + 2699
    frame #17: 0x00007fff23bce066 CoreFoundation`CFRunLoopRunSpecific + 438
    frame #18: 0x000000010207ba6a EarlGrey`-[GREYRunLoopSpinner grey_drainRunLoopInActiveModeAndCheckCondition:forTime:](self=0x0000600002b84240, _cmd="grey_drainRunLoopInActiveModeAndCheckCondition:forTime:", stopConditionBlock=0x00000001020c9560, time=1.7976931348623157E+308) at GREYRunLoopSpinner.m:175:31
    frame #19: 0x000000010207b435 EarlGrey`-[GREYRunLoopSpinner spinWithStopConditionBlock:](self=0x0000600002b84240, _cmd="spinWithStopConditionBlock:", stopConditionBlock=0x00000001020c9560) at GREYRunLoopSpinner.m:58:26
    frame #20: 0x00000001020c8cba EarlGrey`-[GREYUIThreadExecutor executeSyncWithTimeout:block:error:](self=0x000060000252c300, _cmd="executeSyncWithTimeout:block:error:", seconds=1.7976931348623157E+308, execBlock=0x0000000101f09f70, error=0x0000000000000000) at GREYUIThreadExecutor.m:227:22
    frame #21: 0x00000001020c8783 EarlGrey`-[GREYUIThreadExecutor executeSync:error:](self=0x000060000252c300, _cmd="executeSync:error:", execBlock=0x0000000101f09f70, error=0x0000000000000000) at GREYUIThreadExecutor.m:198:10
    frame #22: 0x0000000101f09f46 Detox`__45-[EarlGreyImpl(.block_descriptor=0x0000600002b4c210) detox_safeExecuteSync:]_block_invoke at EarlGrey+Detox.m:17:3
    frame #23: 0x00007fff23bd429c CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    frame #24: 0x00007fff23bd3a08 CoreFoundation`__CFRunLoopDoBlocks + 312
    frame #25: 0x00007fff23bce894 CoreFoundation`__CFRunLoopRun + 1284
    frame #26: 0x00007fff23bce066 CoreFoundation`CFRunLoopRunSpecific + 438
    frame #27: 0x00007fff384c0bb0 GraphicsServices`GSEventRunModal + 65
    frame #28: 0x0000000101f0f8da Detox`__detox_UIApplication_run(self=0x00007fb6f0100900, _cmd="_run") at ReactNativeSupport.m:143:9
    frame #29: 0x00007fff48092d4d UIKitCore`UIApplicationMain + 1621
    frame #30: 0x00000001008d6930 DetoxTestApp`main(argc=1, argv=0x00007ffeef329c80) at main.m:14:12
    frame #31: 0x00007fff5227ec25 libdyld.dylib`start + 1
(lldb) 
运行测试时的终端日志:
detox[17781] DEBUG: [DetoxServer.js/CANNOT_FORWARD] role=testee not connected, cannot fw action (sessionId=7f3c526f-ba61-1c9e-8937-d08d09665fba)
detox[17781] DEBUG: [DetoxServer.js/LOGIN] role=testee, sessionId=7f3c526f-ba61-1c9e-8937-d08d09665fba
detox[17781] DEBUG: [DetoxServer.js/LOGIN_SUCCESS] role=testee, sessionId=7f3c526f-ba61-1c9e-8937-d08d09665fba
detox[17781] INFO:  <Login />: should expect email input
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.facebook.react.ShadowQueue
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.facebook.react.ShadowQueue
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync WXRunLoopIdlingResource: React Native thread is busy.
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.facebook.react.ShadowQueue
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync WXRunLoopIdlingResource: React Native thread is busy.
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[17781] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[17781] INFO:  <Login />: should expect email input [FAIL]

detox[17781] WARN:  [Client.js/PENDING_REQUESTS] App has not responded to the network requests below:
  (id = 1) invoke: {"target":{"type":"Invocation","value":{"target":{"type":"EarlGrey","value":"instance"},"method":"detox_selectElementWithMatcher:","args":[{"type":"Invocation","value":{"target":{"type":"Class","value":"GREYMatchers"},"method":"matcherForAccessibilityID:","args":[{"type":"NSString","value":"email-input"}]}}]}},"method":"assertWithMatcher:","args":[{"type":"Invocation","value":{"target":{"type":"Class","value":"GREYMatchers"},"method":"matcherForSufficientlyVisible","args":[]}}]}
  (id = -1000) isReady: {}

That might be the reason why the test "<Login /> should expect email input" has timed out.

detox[17781] DEBUG: [DetoxServer.js/DISCONNECT] role=tester, sessionId=7f3c526f-ba61-1c9e-8937-d08d09665fba
detox[17781] DEBUG: [DetoxServer.js/DISCONNECT] role=testee, sessionId=7f3c526f-ba61-1c9e-8937-d08d09665fba
detox[17781] DEBUG: [DetoxServer.js/CANNOT_FORWARD] role=tester not connected, cannot fw action (sessionId=7f3c526f-ba61-1c9e-8937-d08d09665fba)
detox[17781] DEBUG: [DetoxServer.js/WS_CLOSE] Detox server connections terminated gracefully
 FAIL  e2e/screen-navigation.test.js (121.37s)
  <Login />
    ✕ should expect email input (60018ms)

  ● <Login /> › should expect email input

    Timeout - Async callback was not invoked within the 60000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 60000ms timeout specified by jest.setTimeout.

      at mapper (../node_modules/jest-jasmine2/build/queueRunner.js:25:45)

  ● <Login /> › should expect email input

    : Timeout - Async callback was not invoked within the 60000ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 60000ms timeout specified by jest.setTimeout.Error:

      12 |   // });
      13 |
    > 14 |   it('should expect email input', async () => {
         |   ^
      15 |     await expect(element(by.id('email-input'))).toBeVisible();
      16 |   });
      17 |

      at new Spec (../node_modules/jest-jasmine2/build/jasmine/Spec.js:116:22)
      at Suite.<anonymous> (screen-navigation.test.js:14:3)
      at Object.<anonymous> (screen-navigation.test.js:2:1)

detox[17778] ERROR: [cli.js] Error: Command failed: node_modules/.bin/jest --config e2e/config.json '--testNamePattern=^((?!:android:).)*$' --maxWorkers 1 e2e

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
我的排毒init.js文件:
const detox = require('detox');
const config = require('../package.json').detox;
const adapter = require('detox/runners/jest/adapter');
const specReporter = require('detox/runners/jest/specReporter');

// Set the default timeout
jest.setTimeout(60 * 1000);

jasmine.getEnv().addReporter(adapter);

// This takes care of generating status logs on a per-spec basis. By default, jest only reports at file-level.
// This is strictly optional.
jasmine.getEnv().addReporter(specReporter);

beforeAll(async () => {
  console.log('**********INITSTART'); // --------------> this is logged
  await detox.init(config, { launchApp: false });
  console.log('**********INITDONE'); // --------------> this is logged
  await device.launchApp({
    newInstance: true,
    launchArgs: {
      detoxPrintBusyIdleResources: 'YES',
    },
  });
  console.log('**********LAUNCHED'); // ------------> this is not logged
});

beforeEach(async () => {
  await adapter.beforeEach();
});

afterAll(async () => {
  await adapter.afterAll();
  await detox.cleanup();
});
如果我不渲染 Navigator 而只是渲染 Normal react 组件(比如),那么一切正常(console.log('**********LAUNCHED') 在 device.launchApp 登录到终端后) .但是,如果我渲染 Navigator,则 console.log('**********LAUNCHED') 不会登录到终端,并且会打印上面粘贴的日志。
版本:
  • react 原生:0.61.5
  • 排毒:16.7.2
  • 开玩笑:24.9.0
  • react-navigation and dependencies:
  • @react-navigation/native: 5.6.1
  • @react-navigation/stack": 5.6.2
  • react 原生手势处理程序:1.6.1
  • react 原生屏幕:2.9.0
  • react-native-reanimated: 1.9.0
  • react 原生安全区域上下文:3.0.7
  • @react-native-community/masked-view: 0.1.10
  • 最佳答案

    我的问题是我们创建的加载组件在加载主页内容之前显示。这是一个无限的动画。正如社区所推荐的那样,您必须模拟动画或在使用 detox 测试时禁用它。
    这是 Detox Github 中此问题的链接
    我禁用了加载动画,它开始工作。

    关于react-native - 使用 React-Navigation 时排毒测试挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62690718/

    相关文章:

    React-Native - 如何在 Native Base 中动态创建选项卡?

    react-native - react native : Build apk file using Expo CLI

    reactjs - 抽屉导航器 : Change Text Color

    react-native - 使用 Hook 以编程方式更新功能组件中的 react 导航标题标题

    Detox::Timeout - 在 jest.setTimeout 指定的 120000 毫秒超时内未调用异步回调

    react-native - 点击作为 SectionList 组件的 subview

    android - AudioManager setCommunicationDevice 不适用于 Android 12

    reactjs - 如何在 React Navigation 5.x 中的不同嵌套堆栈之间导航?

    android - Android 上的 Detox 构建失败 : Error while dexing

    android - 在 Android 4.4.2 和 4.2.2 上使用 React Native 组件时出现错误