NestJSのe2eテストで以下のメッセージが出てテストの応答がとても遅い事象が発生しました。
む
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.この問題は、e2eテストのファイルに以下を追記することで解決します。
afterEach(async () => {
await app.close();
});
上記を書かないと、テスト項目ごとにデータベースへのセッションをはりにいってしまうため、以下のエラーメッセージがでてテストに失敗します。む
[Nest] 33348 - 2021/11/05 9:21:04 ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)... AlreadyHasActiveConnectionError: Cannot create a new connection named "default", because connection with such name already exist and it now has an active connection session.