cypress-nextjs-auth0
cypress-nextjs-auth0 copied to clipboard
feat: cache sessions for multiple users
Description
Closes #25
Serve encrypted sessions directly from an in-memory cache, performing a full login when necessary on a cache miss. This should happen only once for each user in a test run, alleviating some pressure on the Auth0 API, particularly in CI environments where multiple copies of the suite may run in parallel.
How to test
The Cypress terminal window will output http logs indicating that a programmatic login has occurred:
POST /oauth/token 200 978.683 ms - -
GET /userinfo 200 409.344 ms - -
I simply ran my Cypress suite of 40 tests against both this branch and main
, and counted how many times these log entries appeared. On main
, I saw 22 instances. On this branch, I saw 9 -- one for each user in the test suite -- without any loss in functionality.
One thing to note: if any test updates the Cypress superdomain, it seems that the Cypress window is reset and the cache is lost. I'm curious if there's another way to store the cache such that it persists across superdomain updates.
Thank you @lukevmorris!
Regarding Cypress superdomain, that's a good call out. I guess my question is how likely it is that the superdomain changes. Per this security documentation the superdomain can't change during a test. I'm OK not supporting the use case of the superdomain changing between tests for now (assuming someone can open an issue if they need that use case supported).
I just ran the test suite and tests are failing but the error seems unrelated to this PR. @natterstefan do you have any insight into why the Github actions test might be failing here?
I'm OK not supporting the use case of the superdomain changing between tests for now
Sounds like a plan! Let me know if I can help at all with the failing tests.