Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detox integration with jest - Jest did not exit one second after the test run has completed. #1046

Closed
scriptMQL opened this issue Nov 15, 2018 · 6 comments

Comments

@scriptMQL
Copy link

Description

hey guys i will run in my project unit test by jest and end to end test by detox. All my jest test work fine , but when i start detox withthe command "detox test -c ios.sim.debug --loglevel verbose" it go until the cleanup function and stop. Then call the "Jest did not exit one second after the test run has completed."

I have test forceExit but it doesn't work. issues387

Steps to Reproduce

to reproduce this issue use this config for jest in the package.json

"jest": { "preset": "react-native", "verbose": true, "testPathIgnorePatterns": [ "node_modules" ], "unmockedModulePathPatterns": [ "node_modules/react/", "node_modules/enzyme/" ], "setupFiles": [ "./config/enzyme.js" ], "snapshotSerializers": [ "enzyme-to-json/serializer" ], "transform": { "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js", "^.+\\.jsx?$": "babel-jest" }, "transformIgnorePatterns": [ "node_modules/(?!react-native|react-navigation)/" ], "testMatch": [ "<rootDir>/**/**/**/__tests__/*.test.js?(x)", "<rootDir>/**/**/**/__tests__/*.test.js" ] },"detox": { "test-runner": "jest", "setupTestFrameworkScriptFile": "./e2e/init.js", "runner-config": "e2e/config.json", "configurations": { "ios.sim.debug": { "binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/dummy.app", "build": "xcodebuild -project ios/dummy.xcodeproj -scheme dummy -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build", "type": "ios.simulator", "name": "iPhone X" } }

following my setup file:

`// config/enzyme.js
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

configure({ adapter: new Adapter() });

`

Additional my config.js and init.js for detox

{ "setupTestFrameworkScriptFile": "./init.js" }

init.js

`
const detox = require('detox');
const config = require('../package.json').detox;
const adapter = require('detox/runners/jest/adapter');
const { execSync } = require('child_process');

execSync('react-native run-ios');
// Set the default timeout
jest.setTimeout(40000);
jasmine.getEnv().addReporter(adapter);
// jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;

beforeAll(async () => {
await detox.init(config);
console.log('********************* INIT.js -> beforeAll');
});

beforeEach(async () => {
await adapter.beforeEach();
console.log('********************* INIT.js -> beforeEach');
});

afterAll(async () => {
console.log('********************* INIT.js -> befor adapter.afterAll');
await adapter.afterAll();
console.log('********************* INIT.js -> after adapter.afterAll / before cleanup');
await detox.cleanup();
console.log('********************* INIT.js -> after cleanup');
console.log('EXIT');
});
`

At last i my e2e test.js

`
/* eslint-disable */
import { recordVideo, killSimctl } from '../init';

describe('panel test', () => {
beforeEach(async () => {
await device.reloadReactNative();
console.log('********************* test.js -> reloadReactNative');
recordVideo();
console.log('********************* test.js -> recordVideo');
});

afterEach(async () => {
    await device.terminateApp();
    console.log('********************* test.js -> terminateApp');
    killSimctl();
    console.log('********************* test.js -> killSimctl');
});


it(' test tabbar onPress !', async () => {
    await element(by.id('GitHub')).tap();
    await expect(element(by.label('GitHub'))).toBeVisible();
    setTimeout(1000);
    await element(by.label('Components')).tap();
    await expect(element(by.label('Components'))).toBeVisible();
    setTimeout(1000);
    await element(by.label('Home')).tap();
    await expect(element(by.label('Home'))).toBeVisible();
    setTimeout(1000);
    await element(by.label('Views')).tap();
    await expect(element(by.label('Views'))).toBeVisible();
    console.log('********************* test.js -> test passed');
});

});
`

Detox, Node, Device, Xcode and macOS Versions

Provide the macOS and Xcode versions you are using, and the device / simulator you tried it on.

  • Detox: 9.0.6
  • React Native: 0.57.5
  • Node: 10.10.0
  • Device: simtl iPhone X
  • Xcode: 9.4
  • macOS: 10.13.6

Device and verbose Detox logs

detox test -c ios.sim.debug --loglevel verbose

configuration="ios.sim.debug" loglevel="verbose" artifactsLocation="artifacts/ios.sim.debug.2018-11-15 09-16-09Z" node_modules/.bin/jest e2e --config=e2e/config.json --maxWorkers=1 '--testNamePattern=^((?!:android:).)*$'

The following commands produced analyzer issues:
Analyze Base/RCTModuleMethod.mm normal x86_64
Analyze RCTImageCache.m normal x86_64
Analyze RCTNetInfo.m normal x86_64
(3 commands with analyzer issues)

detox[76121] INFO: [DetoxServer.js] server listening on localhost:61140...
detox[76121] DEBUG: [AsyncWebSocket.js/WEBSOCKET_OPEN] opened web socket to: ws://localhost:61140
detox[76121] DEBUG: [DetoxServer.js/LOGIN] role=tester, sessionId=c4494a8d-2dbd-47f2-c835-d04eb5ced034
detox[76121] DEBUG: [DetoxServer.js/LOGIN_SUCCESS] role=tester, sessionId=c4494a8d-2dbd-47f2-c835-d04eb5ced034
detox[76121] DEBUG: [exec.js/EXEC_CMD, #0] /usr/bin/xcrun simctl list -j
detox[76121] DEBUG: [exec.js/EXEC_CMD, #1] applesimutils --list --byType "iPhone X" --byOS "11.4"
detox[76121] DEBUG: [exec.js/EXEC_TRY, #1] Searching for device matching iPhone X...
detox[76121] DEBUG: [exec.js/EXEC_CMD, #2] applesimutils --list --byId "6CE321B7-F402-4667-B4E8-4284836B7FFB"
detox[76121] DEBUG: [exec.js/EXEC_CMD, #3] /usr/bin/xcrun simctl uninstall 6CE321B7-F402-4667-B4E8-4284836B7FFB org.reactjs.native.example.dummy
detox[76121] DEBUG: [exec.js/EXEC_TRY, #3] Uninstalling org.reactjs.native.example.dummy...
detox[76121] DEBUG: [exec.js/EXEC_SUCCESS, #3] org.reactjs.native.example.dummy uninstalled
detox[76121] DEBUG: [exec.js/EXEC_CMD, #4] /usr/bin/xcrun simctl install 6CE321B7-F402-4667-B4E8-4284836B7FFB "/Users/pascal/Documents/GitLab/component-library-explorer-s
ovanta/ios/build/Build/Products/Debug-iphonesimulator/dummy.app"
detox[76121] DEBUG: [exec.js/EXEC_TRY, #4] Installing /Users/pascal./Documents/GitLab/dummy/ios/build/Build/Products/Debug-iphonesimulator/dummy.app...
detox[76121] DEBUG: [exec.js/EXEC_SUCCESS, #4] /Users/pascal.renner/Documents/GitLab/dummy/ios/build/Build/Products/Debug-iphonesimulator/RNLibraryE
xplorerSovanta.app installed
detox[76121] DEBUG: [exec.js/EXEC_CMD, #5] /usr/bin/xcrun simctl terminate 6CE321B7-F402-4667-B4E8-4284836B7FFB org.reactjs.native.example.dummy
detox[76121] DEBUG: [exec.js/EXEC_TRY, #5] Terminating org.reactjs.native.example.dummy...
detox[76121] DEBUG: [exec.js/EXEC_SUCCESS, #5] org.reactjs.native.example.dummy terminated
detox[76121] DEBUG: [exec.js/EXEC_CMD, #6] /bin/cat /dev/null >/Users/pascal/Library/Developer/CoreSimulator/Devices/6CE321B7-F402-4667-B4E8-4284836B7FFB/data/tmp/detox.l
ast_launch_app_log.out 2>/Users/pascal/Library/Developer/CoreSimulator/Devices/6CE321B7-F402-4667-B4E8-4284836B7FFB/data/tmp/detox.last_launch_app_log.err && SIMCTL_CHILD
_DYLD_INSERT_LIBRARIES="/Users/pascal/Library/Detox/ios/8fda9ea8145fa9ba6f1cc9b085eed5d8c6f7bc77/Detox.framework/Detox" /usr/bin/xcrun simctl launch --stdout=/tmp/detox.last_launch_app_log.out --stderr=/tmp/detox.last_launch_app_log.err 6CE321B7-F402-4667-B4E8-4284836B7FFB org.reactjs.native.example.dummy --args -detoxServer ws://localhost:61140 -detoxSessionId c4494a8d-2dbd-47f2-c835-d04eb5ced034
detox[76121] DEBUG: [exec.js/EXEC_TRY, #6] Launching org.reactjs.native.example.dummy...
detox[76121] DEBUG: [exec.js/EXEC_SUCCESS, #6] org.reactjs.native.example.dummy launched. The stdout and stderr logs were recreated, you can watch them with:
tail -F /Users/pascal/Library/Developer/CoreSimulator/Devices/6CE321B7-F402-4667-B4E8-4284836B7FFB/data/tmp/detox.last_launch_app_log.{out,err}
detox[76121] DEBUG: [DetoxServer.js/CANNOT_FORWARD] role=testee not connected, cannot fw action (sessionId=c4494a8d-2dbd-47f2-c835-d04eb5ced034)
detox[76121] DEBUG: [DetoxServer.js/LOGIN] role=testee, sessionId=c4494a8d-2dbd-47f2-c835-d04eb5ced034
detox[76121] DEBUG: [DetoxServer.js/LOGIN_SUCCESS] role=testee, sessionId=c4494a8d-2dbd-47f2-c835-d04eb5ced034
console.log e2e/init.js:15
********************* INIT.js -> beforeAll

console.log e2e/init.js:20
********************* INIT.js -> beforeEach

console.log e2e/e2e/template.e2e.test.js:7
********************* test.js -> reloadReactNative

detox[76121] DEBUG: [exec.js/EXEC_CMD, #7] /usr/bin/xcrun simctl terminate 6CE321B7-F402-4667-B4E8-4284836B7FFB org.reactjs.native.example.dummy
detox[76121] DEBUG: [exec.js/EXEC_TRY, #7] Terminating org.reactjs.native.example.dummy..
detox[76121] DEBUG: [exec.js/EXEC_SUCCESS, #7] org.reactjs.native.example.dummy terminated
console.log e2e/e2e/template.e2e.test.js:14
********************* test.js -> terminateApp

console.log e2e/init.js:24
********************* INIT.js -> befor adapter.afterAll

console.log e2e/init.js:26
********************* INIT.js -> after adapter.afterAll / before cleanup

detox[76121] DEBUG: [DetoxServer.js/DISCONNECT] role=testee, sessionId=c4494a8d-2dbd-47f2-c835-d04eb5ced034
FAIL e2e/e2e/template.e2e.test.js
● Test suite failed to run

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

  at mapper (../node_modules/jest-jasmine2/build/queue_runner.js:41:52)

Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 177.589s
Ran all test suites matching /e2e/i with tests matching "^((?!:android:).)*$".
Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with --detectOpenHandles to troubleshoot this issue.

@stevechun
Copy link

As a workaround, try detox test -c ios.sim.debug --forceExit
If this doesn't work, the you can try manually setting --forceExit on detox/local-cli/detox-test.js line 135, directly to jest command.

@rotemmiz
Copy link
Member

There's too much configuration here to try reproducing it outside your project.
If you believe this is a bug in Detox please create a small demo project that recreates this bug, and share with with us.

@scriptMQL
Copy link
Author

@stevechun if I run detox test -c ios.sim.debug --forceExit became this error =>

error: unknown option `--forceExit'.

if I add "force":true in config.json then it throw this message =>

Force exiting Jest
Have you considered using --detectOpenHandles to detect async operations that kept running
after all tests finished?

@rotemmiz i have create simple git repo (https://github.com/scriptMQL/testProject) with the same issue

@scriptMQL
Copy link
Author

its not an issue about detox. it was an issue in my code.

@heleneyuan
Copy link

heleneyuan commented Nov 19, 2018

Met the same issue. How did you resolve this? @scriptMQL

@scriptMQL
Copy link
Author

i had an issue in my code
before:
`

import { recordVideo, killSimctl } from '../helper';

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

afterEach(async () => {
await device.terminateApp();
killSimctl();
});

it(' test tabbar onPress !', async () => {
await element(by.id('GitHub')).tap();
await expect(element(by.label('GitHub'))).toBeVisible();
setTimeout(1000);
await element(by.label('Components')).tap();
await expect(element(by.label('Components'))).toBeVisible();
setTimeout(1000);
await element(by.label('Home')).tap();
await expect(element(by.label('Home'))).toBeVisible();
setTimeout(1000);
await element(by.label('Views')).tap();
await expect(element(by.label('Views'))).toBeVisible();
});`

after:

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

afterEach(async () => {

});

it(' test tabbar onPress !', async () => {
await element(by.id('GitHub')).tap();
await expect(element(by.label('GitHub'))).toBeVisible();
});

i have remove my helper functions and the test are running. So I will refactor my code.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants