You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
I want to run a global set up (creating the database and seeding it) before executing any test files.
I don't want to run them in every test file, I only need to run them once. I can't seem to find a way to do this.
Related issues
Guide / Sample for integration Testing [Jest] #5308
So current problem is only how to pass connection properly so typeorm only uses 1 connection on multiple jest workers.
I'm having the same issue. When the connection is created in jest globalSetup it cannot be found within the tests. It's like the tests are running in a sandbox mode.
Using globalSetup and globalTeardown with TypeScript
The code to create a connection and close it should be executed before all tests and after all tests are done, that's why we've added it to globalSetup.ts and globalTeardown.ts:
It is better to have two separate test environments (two test databases),
one for testing resolvers (which is closer to an integration test), and the other for testing everything else.
When testing graphql resolvers, seeding the database should only be done once as this is a slow operation.
Currently, using 'globalSetup` and `globalTeardown` with jest doesn't work for setting up the `typeorm` database.
The tests are not able to find the connection.
See:
#73typeorm/typeorm#5308jestjs/jest#10178
It is also not efficient to remove all of the entries for this database in order to start with a clean slate for
testing the models and testing the seeding operations. So what we do here is we have two test databases.
1. a prepopulated frozen test database (called `test_db`) to be used by the graphql resolvers
2. an empty database (called `empty_test_db`) which we can safely mutate (like inserting and deleting operation) to test seeding functions, among others
So this pull request updates all the scripts and other files for the current tests to work
I have also refactored some of the test scripts to be more readable and also added
a simple test for testing the `abilityById` graphql query..
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I want to run a global set up (creating the database and seeding it) before executing any test files.
I don't want to run them in every test file, I only need to run them once. I can't seem to find a way to do this.
Related issues
Guide / Sample for integration Testing [Jest] #5308
typeorm/typeorm#5308
Using globalSetup and globalTeardown with TypeScript
jestjs/jest#10178
Organizing tests
https://homoly.me/posts/organizing-tests-with-jest-projects
Current test performance
The text was updated successfully, but these errors were encountered: