Has anybody successfully set up SuperTokens for E2...
# support-questions-legacy
e
Has anybody successfully set up SuperTokens for E2E testing with a Nest.js backend? I can't for the life of me get supertokens to initialize properly, or at all. I've followed the integration docs for Nest.js, and have set up a
SupertokensService
with a constructor that calls
supertokens.init({ ... config ... })
. This setup works great in both development and production. Among other things, we use
Session.getSession
during request processing. But for any request I send during an E2E test, I get an
Initialisation not done. Did you forget to call the SuperTokens.init function?
error. Also, the
/auth/signin
routes are not available. I've resorted to logging:
Copy code
console.log('pre-init')
supertokens.init( ... )
console.log('post-init')
and sure enough, I can see my custom init logs, but still supertokens remains uninitialized. I've set
DEBUG=com.supertokens
, but this gives me nothing in the E2E test.
r
hey @eliasbemlo are you resetting the supertokens instance anywhere? The fact that the not initialised error is coming means that the superotkens singleton is undefined during the testing
e
Not in any way I'm aware. As part of pre-processing a request, we do
Session.getSession(...)
. This is what throws the "Not initialized" error. But even if I change it to:
Copy code
supertokens.init(...)
Session.getSession(...)
I still get the error.
r
What are the contents of supertokens.init?
Does it have session.init in the recipeList?
e
Yes, of course. It's initializing
Session
,
ThirdParty
,
EmailPassword
,
UserMetadata
and
Dashboard
recipes. Like I said, it's working fine when running the development server. I'll see if I can set up a minimal reproduction repo.
I tried to reproduce it here, but failed: https://github.com/eliasnorrby/nestjs-supertokens-e2e-reproduction Here, SuperTokens does properly initialize during the E2E test suite. I'm looking into what we're doing in our E2E setup that make produce a difference in behaviour.
Solved it. Turns out I was running
supertokens.init
twice – once during the seeding script before bootstrapping the backend, and once inside the backend. In the seed script,
Session
was not initialized. Ensuring
init
is only called once seemed to have resolved the issue.
r
hey @eliasbemlo apologies for being MIA. Im glad that you fixed it 🙂
e
No worries, your questions lead me to the solution anyway! 😄
17 Views