#e2e Testing - Have 1 BeforeAll to start App and afterAll to close app

12 messages · Page 1 of 1 (latest)

small ruin
#

Hi.

I tried to look into it for a few days but with no success.

We have a situation where we have a lot of tests suites.
Unfortunately beforeAll every test suite we start the app and after all we close the app.

We are trying find beforeAllSuite hook that we can start the App and afterAllSuites to close the app

This will increase the tests time and memory consumption to a different level and because we have a lot of tests it takes a lot of time

Anyone know something we can use?

I also searched on the Nest but with no success

fallow lance
#

Hi @small ruin, I'd recommend you not to use the same app for all your test suites.
Some of your test suites might use a specific module rather than another, and so your app must be created using a different compiled testing module.

E2E tests will take time to execute no matter what. They're heavy by design ; or at least way more heavier than unit tests.

But maybe your tests consume way more memory or takes way too long to execute. If so there might be one or more memory leaks somewhere. This you can fix! There are tools to monitor this kind of behavior.

small ruin
#

We are using only E2E. We start the app and all the tests are integration testing (e2e). All tests start the app and send HTTP / WS request and we need the app up and running

Regarding memory leak we already examined it and there is nothing suspicious.

I just need to start the App when tests are starting and stop when all tests are finished.
We have something similar in another project when using HapiJS and Mocha but generally speaking this is not something special and i do expect to have it on NestJS with Jest.
I just cannot find it anywhere

fallow lance
small ruin
#

Anyone else knows what i can do here?
Doesn't make any sense that this simple and straights forward feature doesn't exist

grave roseBOT
small ruin
#

I have double checked myself many times.
I create a test where nothing happen only the createTestingModule and createNestApplication

Once i close the test i do "app.close()" but when i take the heapdump the nestjs app still there.

I have ran with 4 suites and saw 5 nestApp in memory
When i changed it to 7 i saw the same beahvior alsthough i am closing the app and even do "app = null" to make sure Jest is not the problem here

flat depot
#

Did you ever find a solution for this?

eternal dagger
#

AFAIK you can't really share state across Jest test files. What we did to speed up our e2e tests in our project is to spin up the app in a testing confihuration separately (it exposes some service endpoint for exampe for clearing the database and such, that are only loaded when NODE_ENV = test). Then the test suite just uses normal http calls to the running applicaiton. After all tests finish, the testing app is torn down. (the whole thing is managed via a bash file)

flat depot
#

Would you mind sharing your bash file with me?

eternal dagger
#

It's proprietary code, but basicall, it goes like this:

export NODE_ENV=test
npm run serve-for-test # this has to continue running in detached mode

while ... # wait for localhost:PORT/ping to return 200, so we know the app is ready

npm run test:e2e # run the actuall e2e tests

kill ... # kill the process listening on PORT