Add tests for SocketModeReceiver (#750)#1012
Conversation
9a281d0 to
177b66d
Compare
Codecov Report
@@ Coverage Diff @@
## main #1012 +/- ##
==========================================
+ Coverage 66.41% 68.48% +2.06%
==========================================
Files 13 13
Lines 1212 1212
Branches 357 357
==========================================
+ Hits 805 830 +25
+ Misses 338 309 -29
- Partials 69 73 +4
Continue to review full report at Codecov.
|
866c15e to
1b6b5d6
Compare
seratch
left a comment
There was a problem hiding this comment.
Looks great to me; You're so quick!
I left a few comments. If you also think we should have one more test case for the stop method, update the test before merging this PR.
Note that we usually merge PRs with squashed one commit (as long as there is no reason to have multiple commits). You can do either force-push with a squashed commit or using the "Squash and merge" button in the GitHub web UI.
| @@ -0,0 +1,288 @@ | |||
| /* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/naming-convention */ | |||
There was a problem hiding this comment.
Adding this test suite is a great start!
In addition to the tests in this PR, we can add a test case to run await receiver#stop(). I know the test won't be a crucial test asset, but it slightly improves the code coverage. On the other hand, we cannot run receiver#start() as it blocks the test execution and the test results in a timeout error.
Also, mainly for your information, let me mention a few other things. As these are nice-to-haves in future development, you don't need to have anything further in this PR.
-
Currently, we don't have any integration tests using both
Appand any of the built-in receivers. App.spec.ts uses onlyFakeReceiver, which does not do anything. We may want to have different ways to ensure the combination of App and a receiver works as we expect. -
(This may be more like an improvement on
@slack/socket-modeside) In the future, we may want to have some tests verifying WebSocket communications (incl. auto-reconnection) and payload handling code. Currently, we don't have any tests for this, even on the@slack/socket-modelibrary side. Having some tests for the pattern will make future development / debugging reported issues.- For your reference, we have some tests and mock WS servers in Python/Java projects:
- https://github.com/slackapi/bolt-python/blob/main/tests/adapter_tests/socket_mode/mock_socket_mode_server.py
- https://github.com/slackapi/python-slack-sdk/blob/main/tests/slack_sdk/socket_mode/mock_socket_mode_server.py
- https://github.com/slackapi/java-slack-sdk/blob/main/bolt-socket-mode/src/test/java/test_locally/SocketModeAppTest.java
- For your reference, we have some tests and mock WS servers in Python/Java projects:
I hope these are helpful to you (and anyone who read this comment!)
misscoded
left a comment
There was a problem hiding this comment.
LGTM! Always happy to have more tests 🙌🏼
From what I can tell, the type of
thiswithin abeforeEachblock isContextwhereas the type ofthiswithin an it block isSuite- so I'm not sure how it works in ExpressReceiver ❓
I believe the cause of it grabbing onto Suite instead of Context is the use of arrow functions (ie, no bound this). Switching them out for function (which is used in the ExpressReceiver tests) is one way to address this and should make it possible to incorporate the beforeEach block to contain the more repetitive bits.
1b6b5d6 to
282637f
Compare
|
Thanks for the reviews @misscoded @seratch !
Thanks for explaining that @misscoded, this is today's edition of "Today I Learned" 😊 . That indeed addressed the issue and I think it looks a bit cleaner now.
Good call @seratch, I've added a very basic test for both
This is super handy @seratch, thanks for pointing it out. I will take some time to read through these and have a think about how bolt-js could follow a similar path to ensure the same level of integration testing coverage.
I've rebased this branch with the latest from Assuming the latest changes are approved by you all, I'm not sure if it is OK to merge my own PR or not on the team (still figuring out The Way We Do Things) but even if that is the case, feel free to merge it in if you think it is acceptable. This was fun 😄 |
|
@filmaj Thanks for having the tests for both start and stop methods. Indeed, we can easily have those using the stub objects for the underlying
You can merge it on your own now but I would like to have the honor of merging your first-ever pull request for this project 😄 Great work 🎉 |
Summary
Saw there was a low priority "add tests for this untested thing" task (#750) so I thought I'd give it a shot! This is a first pass at adding tests for the
SocketModeReceivermodule.I did have trouble replicating the way the e.g.
ExpressReceivertest create a newFakeServerinstance in itsbeforeEachsetup method. When I tried to use the same approach, I would get this TypeScript error:By moving the FakeServer instantiation to within the test, that avoided the issue - though I'd like to keep the test style consistent across test files if possible! Not sure why copying the approach from
ExpressReceiverdidn't work for me 🤔 . From what I can tell, the type ofthiswithin abeforeEachblock isContextwhereas the type ofthiswithin anitblock isSuite- so I'm not sure how it works inExpressReceiver❓Requirements (place an
xin each[ ])