-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(backend): configure db per jest worker #45
Conversation
@@ -22,10 +22,14 @@ describe('Account Service', (): void => { | |||
const mockMessageProducer = { | |||
send: jest.fn() | |||
} | |||
const overrideConfig = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this instead happen in createTestApp
like how it currently is in main
(what I removed in the testcontainers pr) instead of each test file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved it to the config file. It's needed when we create the IoC container, which happens before createTestApp
is run.
packages/backend/jest.setup.js
Outdated
@@ -7,6 +7,8 @@ const POSTGRES_PORT = 5432 | |||
const REDIS_PORT = 6379 | |||
|
|||
module.exports = async () => { | |||
const workers = parseInt(process.env.JEST_WORKERS || '1') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the number of actual workers exceeds process.env.JEST_WORKERS
?
It'd be nice if jest had a way for the global setup file to know the number of workers, but I'm not seeing one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this defaults to the number of the cores available on your machine minus one for the main thread.
Could we ditch process.env.JEST_WORKERS
and calculate that default value ourselves?
const workers = parseInt(process.env.JEST_WORKERS || '1') | |
const workers = os.cpus().length - 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could just write a script that counts how many test files there are rather.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we ditch process.env.JEST_WORKERS and calculate that default value ourselves?
Didn't see that, that could work 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, maxWorkers
is accessible in globalSetup:
This function gets Jest's
globalConfig
object as a parameter.
So no computation required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function gets Jest's globalConfig object as a parameter.
That's not actually accessible from the function, that's just for storing global values like db configs that need to be accessed in teardown.
Co-authored-by: Brandon Wilson <brandon@coil.com>
* feat(connector): use testcontainers * feat(accounts): use testcontainers * feat(backend): use testcontainers * chore(tests): run testcontainers if no database configuration * test(backend): configure db per jest worker (#45) * test(backend): configure db per jest worker * refactor: move test db name into config * fix: replace JEST_WORKERS with os cpu count * fix: use globalConfig for maxWorkers Co-authored-by: Brandon Wilson <brandon@coil.com> Co-authored-by: Brandon Wilson <brandon@coil.com> * test(connector): configure redis db per jest worker Co-authored-by: Cairin Michie <cairinmichie@gmail.com>
Changes proposed in this pull request
Context
Checklist
fixes #number