Open M-Scott-Lassiter opened 1 year ago
I am not familiar with supertest, but it looks like your beforeAll
and afterAll
hooks aren't waiting for db.connect
to finish. The database connection is synchronous when using the memory store, but asynchronous when using MySQL store.
Current Behavior
I have a test suite that uses Jest. When I use the default memory session storage, all my tests work fine. When I upgraded to this package for session storage, a bunch of the tests broke. However, with manual testing everything is still working as designed.
I inserted a bunch of
console.log
calls everywhere and I've narrowed the problem down to when I call thereq.login
function in my route (simplified example code):The test looks something like this:
The route is setup something like this:
The
app.js
has a session store configuration like this.Commenting out the
store
key reverts Express to using the MemoryStore method and the test works again with allconsole.log
statements outputting as expected.When the
MySQLStore
store is used during the test, it console logs all the way up toLOGGING IN USER
, then nothing. The test then fails with the erroras well as telling me
Expected Behavior
The test should successfully complete just like the MemoryStore test does. If this is not possible, there should be documentation to show how to test the functionality works as desired.
Cross reference to Stack Overflow post: Express App Test Suite with Supertest Breaks when switching from MemoryStore to express-mysql-session