2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Firebase functions とJestの組み合わせで正しく終了させる

Last updated at Posted at 2020-02-21

備忘録のメモです.
以下の環境でテストを書いてたら、Jestの終了に時間がかかりメッセージが出力されてました.

  • @firebase/testing 0.16.5
  • @firebase/functions 0.4.29
  • Jset 24.9.0

以下の様なメッセージになってるため、非同期処理がうまくできてない感じだけは分かった.

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.

Jestのドキュメントと、@firebase/functions のコードを読みあさって以下の仕様を見つけました.

1秒未満で終了させれば警告が出なくなるので以下の様に書き直せばOKです :tada:
ここでは900msに設定しました.

const testFuncs = firebase.initializeTestApp(config);
const functions = testFuncs.functions();
functions.useFunctionsEmulator("http://localhost:5001");

// timeoutを指定
const func = functions.httpsCallable('func', { timeout: 900 });
const res = await func({ path: "hello" });

1秒未満でどうしてもタイムアウトする場合は、 --detectOpenHandles を指定してタイムアウトを伸ばす方法もあります.

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?