ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Jest did not exit one second after the test run has completed.
    테스팅/JEST 2019. 11. 6. 16:36

    1. 문제

    HTTP API 통신 테스트를 하다가 다음과 같은 경고를 만났다.

     

    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.

     

     

    2. 해결

    테스트 실행 완료 후 1초 동안 Jest가 종료되지 않았다.

    이 뜻은 테스트의 비동기 작업들이 종료되지 않았다는 것이다. 

    그래서 Jest를 실행할 때, '--detectOpenHandles' 옵션을 사용하는 것을 고려해보라는 의미다.

     

    --detectOpenHandles

    Jest가 깔끔하게 종료되는 것을 막는 열려있는 핸들들을 출력하고 수집하려고 시도하는 옵션이다.

    이 옵션은 --forceExit 옵션이 필요할 때 사용하면 된다.

    단, 해당 옵션은 내부적으로 async_hooks을 사용하기 때문에 Node 8 버전 이상에서만 사용할 수 있는 옵션이며, 퍼포먼스에 페널티가 있어서 반드시 디버깅할 때에만 사용하라고 권고하고 있다.

     

     

    https://jestjs.io/docs/en/cli#detectopenhandles

     

    Jest · 🃏 Delightful JavaScript Testing

    🃏 Delightful JavaScript Testing

    jestjs.io

     

     

    package.json

    {
        ...
        "scripts": {
            "test": "jest --detectOpenHandles --forceExit"
        }
    }

     

    위와 같이 테스트 스크립트를 설정하고 사용하면 테스트가 완료되면 프로세스를 강제로 종료시키며, 해당 경고가 발생하지 않는다.

    '테스팅 > JEST' 카테고리의 다른 글

    [supertest] express-session 테스트는 어떻게 할까?  (0) 2019.11.01
    jest-validate  (0) 2019.10.31
    jest-get-type  (0) 2019.10.31
    jest-docblock  (0) 2019.10.31
    jest-diff  (0) 2019.10.31
Designed by Tistory.