detox init не работает при запуске тестов detox response-native с travis CI - PullRequest
0 голосов
/ 03 августа 2020

Я не могу понять, почему функция детоксикации init не работает в тестовой части моего travis CI pieline.

соответствующий пакет. json информация:

"build:ios": "detox build -c ios.sim.debug",
"test:ios": "detox test -c ios.sim.debug",
...
"react-native": "^0.63.2",
"detox": "^17.3.4",
...
  "detox": {
    "test-runner": "jest",
    "configurations": {
      "ios.sim.debug": {
        "binaryPath": "./ios/build/Build/Products/Debug-iphonesimulator/unmasked.app",
        "build": "xcodebuild -workspace ios/unmasked.xcworkspace -configuration Debug -scheme unmasked -sdk iphonesimulator -derivedDataPath ios/build -quiet",
        "type": "ios.simulator",
        "name": "iPhone 11"
      }
    }
  },
...

detox init. js

import detox from 'detox';
import adapter from 'detox/runners/jest/adapter';
import specReporter from 'detox/runners/jest/specReporter';
import { detox as config } from '../package.json';

// Set the default timeout
jest.setTimeout(120000);

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 () => {
  await detox.init(config);
  await device.launchApp({ newInstance: false, permissions: { notifications: 'YES' } });
}, 300000);

beforeEach(async () => {
  try {
    await adapter.beforeEach();
  } catch (err) {
    // Workaround for the 'jest-jasmine' runner (default one): if 'beforeAll' hook above fails with a timeout,
    // unfortunately, 'jest' might continue running other hooks and test suites. To prevent that behavior,
    // adapter.beforeEach() will throw if detox.init() is still running; that allows us to run detox.cleanup()
    // in that emergency case and disable calling 'device', 'element', 'expect', 'by' and other Detox globals.
    // If you switch to 'jest-circus' runner, you can omit this try-catch workaround at all.

    await detox.cleanup();
    throw err;
  }
});

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

e2e / config. js

{
    "setupFilesAfterEnv": ["./init.js"],
    "testEnvironment": "node",
    "reporters": ["detox/runners/jest/streamlineReporter"],
    "verbose": true
}

тест

describe('Example test', () => {
  beforeEach(async () => {
    await device.reloadReactNative();
  });

  it('can sign in', async () => {
      // nothing even here
  });
});

файл travis

env:
  global:
    - NODE_VERSION=14
cache:
  - node_modules
  - ios/Pods
language: objective-c
os: osx
osx_image: xcode11.3
install:
  - brew update
  - brew install yarn
  - brew tap wix/brew
  - brew install applesimutils
  - yarn --ignore-engines
  - cd ios; pod install; cd -
script:
  - yarn lint
  - travis_wait yarn build:ios
  - yarn detox clean-framework-cache
  - yarn detox build-framework-cache
  - yarn test:ios --cleanup

конец вывода travis

The command "yarn detox build-framework-cache" exited with 0.
311.85s$ yarn test:ios --cleanup
yarn run v1.22.4
$ detox test -c ios.sim.debug --cleanup
detox[91515] INFO:  [test.js] configuration="ios.sim.debug" cleanup=true reportSpecs=true useCustomLogger=true forceAdbInstall=false DETOX_START_TIMESTAMP=1596426699509 node_modules/.bin/jest --config e2e/config.json '--testNamePattern=^((?!:android:).)*$' --maxWorkers 1 e2e
detox[91516] INFO:  [DetoxServer.js] server listening on localhost:50934...
detox[91516] INFO:  [AppleSimUtils.js] org.reactjs.native.unmasked launched. To watch simulator logs, run:
        /usr/bin/xcrun simctl spawn CFD335EF-9279-4FD8-95A0-DFA1C19E3DA9 log stream --level debug --style compact --predicate 'process == "unmasked"'
detox[91516] INFO:  Example test: can sign in
detox[91516] ERROR: [DetoxExportWrapper.js/DETOX_INIT_ERROR] 
 DetoxRuntimeError: Aborted detox.init() execution, and now running detox.cleanup()
HINT: Most likely, your test runner is tearing down the suite due to the timeout error
    at Detox.[_assertNoPendingInit] (/Users/travis/build/dali-lab/unmasked/node_modules/detox/src/Detox.js:204:9)
    at Detox.beforeEach (/Users/travis/build/dali-lab/unmasked/node_modules/detox/src/Detox.js:111:37)
    at DetoxExportWrapper.<computed> (/Users/travis/build/dali-lab/unmasked/node_modules/detox/src/DetoxExportWrapper.js:87:32)
    at DetoxAdapterImpl.beforeEach (/Users/travis/build/dali-lab/unmasked/node_modules/detox/runners/jest/DetoxAdapterImpl.js:17:22)
    at DetoxAdapterJasmine.beforeEach (/Users/travis/build/dali-lab/unmasked/node_modules/detox/runners/jest/DetoxAdapterJasmine.js:19:5) {
  name: 'DetoxRuntimeError'
}
detox[91516] WARN:  [Client.js/PENDING_REQUESTS] App has not responded to the network requests below:
  (id = -1000) isReady: {}
Unresponded network requests might result in timeout errors in Detox tests.
detox[91516] INFO:  Example test: can sign in [FAIL]
FAIL e2e/tests/example.spec.js (309.753 s)
  Example test
    ✕ can sign in (7960 ms)
  ● Example test › can sign in
    Timeout - Async callback was not invoked within the 300000 ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 300000 ms timeout specified by jest.setTimeout.
      at mapper (../node_modules/jest-jasmine2/build/queueRunner.js:29:45)
  ● Example test › can sign in
    DetoxRuntimeError: Aborted detox.init() execution, and now running detox.cleanup()
    HINT: Most likely, your test runner is tearing down the suite due to the timeout error
      at Detox.[_assertNoPendingInit] (../node_modules/detox/src/Detox.js:204:9)
      at Detox.beforeEach (../node_modules/detox/src/Detox.js:111:37)
      at DetoxExportWrapper.<computed> (../node_modules/detox/src/DetoxExportWrapper.js:87:32)
      at DetoxAdapterImpl.beforeEach (../node_modules/detox/runners/jest/DetoxAdapterImpl.js:17:22)
      at DetoxAdapterJasmine.beforeEach (../node_modules/detox/runners/jest/DetoxAdapterJasmine.js:19:5)
  ● Example test › can sign in
    DetoxRuntimeError: Aborted detox.init() execution, and now running detox.cleanup()
    HINT: Most likely, your test runner is tearing down the suite due to the timeout error
      at Detox.[_assertNoPendingInit] (../node_modules/detox/src/Detox.js:204:9)
      at Detox.beforeEach (../node_modules/detox/src/Detox.js:111:37)
      at DetoxExportWrapper.<computed> (../node_modules/detox/src/DetoxExportWrapper.js:87:32)
      at DetoxAdapterImpl.beforeEach (../node_modules/detox/runners/jest/DetoxAdapterImpl.js:17:22)
      at DetoxAdapterJasmine.beforeEach (../node_modules/detox/runners/jest/DetoxAdapterJasmine.js:19:5)
  ● Example test › can sign in
    DetoxRuntimeError: Detox instance has not been initialized
    HINT: There was an error on attempt to call detox.init()
    DetoxRuntimeError: Aborted detox.init() execution, and now running detox.cleanup()
    HINT: Most likely, your test runner is tearing down the suite due to the timeout error
      1 | describe('Example test', () => {
      2 |   beforeEach(async () => {
    > 3 |     await device.reloadReactNative();
        |           ^
      4 |   });
      5 | 
      6 |   it('can sign in', async () => {
      at Detox.[_assertNoPendingInit] (../node_modules/detox/src/Detox.js:204:9)
      at Detox.beforeEach (../node_modules/detox/src/Detox.js:111:37)
      at DetoxExportWrapper.<computed> (../node_modules/detox/src/DetoxExportWrapper.js:87:32)
      at DetoxAdapterImpl.beforeEach (../node_modules/detox/runners/jest/DetoxAdapterImpl.js:17:22)
      at DetoxAdapterJasmine.beforeEach (../node_modules/detox/runners/jest/DetoxAdapterJasmine.js:19:5)
      at MissingDetox.throwError (../node_modules/detox/src/utils/MissingDetox.js:67:11)
      at Object.device (../node_modules/detox/src/utils/MissingDetox.js:46:16)
      at _callee$ (tests/example.spec.js:3:11)
      at tryCatch (../node_modules/regenerator-runtime/runtime.js:63:40)
      at Generator.invoke [as _invoke] (../node_modules/regenerator-runtime/runtime.js:293:22)
      at Generator.next (../node_modules/regenerator-runtime/runtime.js:118:21)
      at tryCatch (../node_modules/regenerator-runtime/runtime.js:63:40)
      at invoke (../node_modules/regenerator-runtime/runtime.js:154:20)
      at ../node_modules/regenerator-runtime/runtime.js:189:11
      at callInvokeWithMethodAndArg (../node_modules/regenerator-runtime/runtime.js:188:16)
      at AsyncIterator.enqueue (../node_modules/regenerator-runtime/runtime.js:211:13)
      at AsyncIterator.next (../node_modules/regenerator-runtime/runtime.js:118:21)
      at Object.exports.async (../node_modules/regenerator-runtime/runtime.js:238:14)
      at Object._callee (tests/example.spec.js:2:14)
detox[91515] 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.
The command "yarn test:ios --cleanup" exited with 1.

При локальном запуске все работает отлично, даже когда я включаю реальный код в свой тестовый пример. Однако в Travis фаза сборки в порядке, но я не могу пройти инициализацию детоксикации. Есть идеи?

...