Db name different for each test file
See original GitHub issueHi,
from Readme I was under impression that if I pass empty object to instance
property I will get random db per file.
If I simply print out the global variables in every test file I am getting: One file:
process.env.MONGO_URL: mongodb://127.0.0.1:56925/3b97e130-dd09-440d-9937-a7442a421da7?
global.__MONGO_URI__: mongodb://127.0.0.1:56925/3b97e130-dd09-440d-9937-a7442a421da7?
global.__MONGO_DB_NAME__: 1ed20263-b27c-42c8-a800-805368f8fdb3
Second file:
process.env.MONGO_URL: mongodb://127.0.0.1:56925/3b97e130-dd09-440d-9937-a7442a421da7?
global.__MONGO_URI__: mongodb://127.0.0.1:56925/3b97e130-dd09-440d-9937-a7442a421da7?
global.__MONGO_DB_NAME__: e2eb11c0-c836-4849-a7fb-568a642e02bf
So its true that db name is random, but its same for all test files, which is not really that much useful. My expectation was that it would be unique db name per test file - interestingly thats what we get in MONGO_DB_NAME, but we still need to create sensible MONGO_URL from it, it seems.
Am I missing something?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:12
- Comments:5
Top Results From Across the Web
how to change DB name (PROD to TEST) - Oracle Communities
Dear Sirs please tell me simple ways to change the db name b'cos I have 2 db's (10g) as same name PROD in...
Read more >Different db for testing in Django? - Stack Overflow
The way I handle this is through having multiple settings files, since I use that to maintain a set of common settings with...
Read more >Why you should cleverly name Database Objects for SQL Unit ...
This article highlights the importance of clever naming of database objects from both development and SQL unit testing point of view.
Read more >Sharing fixtures - ScalaTest
A test fixture is composed of the objects and other artifacts (files, sockets, database connections, etc.) tests use to do their work.
Read more >Db - Codeception - Documentation
Alternatively, you can enable Db module in suite configuration file and run ... before each test populator: 'mysql -u $user -h $host $dbname...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The readme examples were changed in this PR but the Jest website still has parallel friendly setup examples.
I believe the examples should be parallel friendly as most people just grab it and go, but later face some unexpected race conditions when for example multiple test files clear the db in parallel.
(setting
db
explicitly to an unique string inbeforeAll
mitigates the race conditions)@vladgolubev what’s your opinion on this?
I agree with you, the variable “MONGO_URI” does not change over different test suites but “MONGO_DB_NAME” variable changes. That’s why, the document mentions two steps :
To make it work, you have to do this : (in order to connect to another database)
When using mongoose, you can do the following
I am volunteer to make a PR. To me, there are two options: