【问题标题】:Unable to do Parallel testing with Detox and Jest无法使用 Detox 和 Jest 进行并行测试
【发布时间】:2022-04-14 06:23:31
【问题描述】:

我在 Stack Overflow 上看到过类似的问题,但我觉得我们没有遇到同样的问题,last question 已经一年没有答案了。

我已按照文档进行操作,我的所有测试都运行良好,但是当我打开 4 个模拟器尝试并行测试时,只有其中一个有反应。

package.json

{
 ...
  "detox": {
    "configurations": {
      "ios.sim.debug": {
        "binaryPath": "ios/build/AppName/Build/Products/Debug-iphonesimulator/AppName.app",
        "build": "xcodebuild -project ios/AppName.xcodeproj -scheme AppName -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
        "type": "ios.simulator",
        "device": {
          "type": "iPhone 11"
        }
      }
    },
    "test-runner": "jest --detectOpenHandles --verbose",
    "runner-config": "tests/detox/jest.config.js"
  }
}

测试/排毒/jest.config.js

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  setupFilesAfterEnv: ['./init.ts']
};

init.ts

import { cleanup, init } from 'detox';
const adapter = require('detox/runners/jest/adapter');

const config = require('../../package.json').detox;

jest.setTimeout(90000);

jasmine.getEnv().addReporter(adapter);

beforeAll(async () => {
  await init(config, { initGlobals: false });
}, 90000);

afterAll(async () => {
  await adapter.afterAll();
  await cleanup();
});

这是我在运行并准备好 4 个 IOS 模拟器后用来开始测试的命令

detox test -l warn -w 4 ./path-to-all-tests

依赖关系

  • MacOS 卡塔利娜
  • 固定版本 11.4
  • 排毒:^16.0.2
  • 开玩笑:^24.9.0
  • ts-jest: ^24.1.0

【问题讨论】:

    标签: react-native jestjs detox


    【解决方案1】:

    --detectOpenHandles 使测试同步运行。

    来自开玩笑的文档:

    --detectOpenHandles

    尝试收集并打印阻止 Jest 退出的打开句柄 干净地。在需要按顺序使用 --forceExit 的情况下使用它 让 Jest 退出以可能追查原因。这意味着 --runInBand,使测试连续运行。使用 async_hooks 实现。此选项具有显着的性能损失,应该只 用于调试。

    https://jestjs.io/docs/cli

    您必须删除它才能并行运行测试

    【讨论】:

      猜你喜欢
      • 2019-06-24
      • 2021-10-15
      • 2018-07-28
      • 2020-03-12
      • 2020-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-04
      相关资源
      最近更新 更多