jeudi 28 mars 2019

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

detox test -c android.emu.debug is throwing error as below as test cases are not running.

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

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


  ReferenceError: device is not defined

  1 | describe('Example', () => {
  2 |   beforeEach(async () => {
> 3 |     await device.reloadReactNative();
    |           ^
  4 |   });
  5 | 
  6 |   // it('should have welcome screen', async () => {

  at device (firstTest.spec.js:3:11)


  at device (firstTest.spec.js:3:11)
  at tryCatch (../node_modules/@babel/runtime/node_modules/regenerator- 
  runtime/runtime.js:62:40)
  at Generator.invoke [as _invoke] 
  (../node_modules/@babel/runtime/node_modules/regenerator- 
  runtime/runtime.js:288:22)
  at Generator.prototype.(anonymous function) [as next] 
  (../node_modules/@babel/runtime/node_modules/regenerator- 
  runtime/runtime.js:114:21)
  at tryCatch (../node_modules/@babel/runtime/node_modules/regenerator- 
  runtime/runtime.js:62:40)
  at invoke (../node_modules/@babel/runtime/node_modules/regenerator- 
  runtime/runtime.js:152:20)
  at ../node_modules/@babel/runtime/node_modules/regenerator- 
  runtime/runtime.js:187:11
  at callInvokeWithMethodAndArg 
  (../node_modules/@babel/runtime/node_modules/regenerator- 
  runtime/runtime.js:186:16)
  at AsyncIterator.enqueue 
  (../node_modules/@babel/runtime/node_modules/regenerator- 
  runtime/runtime.js:209:13)
  at AsyncIterator.prototype.(anonymous function) [as next] 
  (../node_modules/@babel/runtime/node_modules/regenerator- 
  runtime/runtime.js:114:21)
  at Object.<anonymous>.runtime.async 
  (../node_modules/@babel/runtime/node_modules/regenerator- 
  runtime/runtime.js:233:14)
  at Object._callee (firstTest.spec.js:2:14)


  ReferenceError: element is not defined

   8 |   // });
   9 | 
  10 |   it('should have splash screen', async () => {
     |                                   ^
  11 |     await expect(element(by.id('splash'))).toBeVisible();
  12 |   });
  13 | 

Detox installation:

npm install detox --save-dev

detox init -r jest

which has created e2e folder with three files looks as below:

fristTest.spec.js

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

it('should have welcome screen', async () => {
    await expect(element(by.id('welcome'))).toBeVisible();
});

it('should show hello screen after tap', async () => {
    await element(by.id('hello_button')).tap();
    await expect(element(by.text('Hello'))).toBeVisible();
});

it('should show world screen after tap', async () => {
    await element(by.id('world_button')).tap();
    await expect(element(by.text('World!!!'))).toBeVisible();
});
});

config.json

{
    "setupTestFrameworkScriptFile": "./init.js",
    "testEnvironment": "node"
}

init.js

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

jest.setTimeout(10000);
jasmine.getEnv().addReporter(adapter);

beforeAll(async () => {
    await detox.init(config);
});

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

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

Details about devDependencies under package.json

"devDependencies": {
"@babel/core": "^7.3.4",
"@babel/preset-env": "^7.4.2",
"babel-jest": "^24.5.0",
"detox": "^12.0.0",
"detox-expo-helpers": "^0.6.0",
"jest": "^24.5.0",
"metro-react-native-babel-preset": "^0.53.1",
"mocha-react-native": "^0.6.0",
"react-test-renderer": "16.8.3",
"redux-mock-store": "^1.5.3"
},
"jest": {
"preset": "react-native"
},
"detox": {
"runner-config": "e2e/config.json",
"configurations": {
  "android.emu.debug": {
    "binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
    "build": "cd android && gradlew assembleDebug assembleAndroidTest - 
 DtestBuildType=debug && cd ..",
    "type": "android.emulator",
    "name": "Nexus_S_API_27"
  },
  "android.emu.release": {
    "binaryPath": "android/app/build/outputs/apk/release/app-release.apk",
    "build": "cd android && ./gradlew assembleRelease assembleAndroidTest 
 -DtestBuildType=release && cd ..",
    "type": "android.attached",
    "name": "Nexus_5X_API_26"
  }
  },
  "test-runner": "jest"
  }

I tried many threads but nothing worked for me. Finally posting from my side, thanks in advance.

Aucun commentaire:

Enregistrer un commentaire