TBD54566975 / dwn-sdk-js

Decentralized Web Node (DWN) Reference implementation
https://identity.foundation/decentralized-web-node/spec/
Apache License 2.0
324 stars 95 forks source link

Add testing util to poll for async event testing #758

Closed LiranCohen closed 2 months ago

LiranCohen commented 2 months ago

Due to the async nature of testing EventStream and Subscriptions, and some external pub/sub systems taking a longer time to publish and/or receive a message, we have added a helper method to help wait for a test case to assert.

Additionally we modified the tests to be able to more accurately check negative test cases where testing the absence of something which arrives async could be challenging.

codecov-commenter commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 98.62%. Comparing base (94da019) to head (2fea4de).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #758 +/- ## ========================================== + Coverage 98.55% 98.62% +0.07% ========================================== Files 73 73 Lines 10929 10929 Branches 1573 1577 +4 ========================================== + Hits 10771 10779 +8 + Misses 152 144 -8 Partials 6 6 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

alanhkarp commented 2 months ago

I needed to test async events on another project. I initially polled to make sure the event had finished, but the tests were taking a long time. Instead, I created a promise in the test code that I resolved in the event handler, and the tests ran 2-3 times faster. I don't know if this approach is appropriate for what you're doing, but I thought I'd mention it.