1. 문제 상황
- jest를 사용해서 coverage를 확인하려던 중, 다음과 같은 에러 창이 나타났다.
A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks. Active timers can also cause this, ensure that .unref() was called on them.
- 문제 상황은 분명 기능 폴더 단위로 테스트를 돌릴 떄에는 테스트 케이스들이 통과되는 것으로 coverage가 측정되는데, 전체 폴더 단위로 커버리지를 측정하면 테스트 케이스들이 특정 시점부터 우수수 실패하기 시작했다.
- 위 에러 내용을 살펴본 바, 간단하게 외부 모듈을 불러오다가 튕긴거다.
- 매 테스트 파일마다 db를 새로 불러오는 코드로 테스트코드가 작성되어 있어서 이런 문제가 생겼던 것이다.
2. 해결 방법
- jest cli 문서를 봐보니,
--runInBand
라는 jest 실행 옵션이 이를 해결해줄 수 있는 것으로 보였다.
- 해당 옵션의 역할은 다음과 같은 내용이다.
Alias: -i. Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests. This can be useful for debugging.
- 내용을 유추하자면, 대략 테스트 실행 시 새로운 프로세스를 만들지 않고 처음 만들어진 프로세스에서 계속 테스트를 실행한다는 것이다.
3. 결과
- 위 유추한 맥락대로, coverage가 의도한 내용대로 잘 출력되었다!
4. 참고자료
https://jestjs.io/docs/cli#--runinband
https://www.inflearn.com/questions/97469