IssueRaiser

Per-worker setup/teardown

## 🚀 Feature Proposal Jest provides _[once-global](https://jestjs.io/docs/en/configuration#globalsetup-string)_ setup and teardown, and _[per-file](https://jestjs.io/docs/en/api#beforeallfn-timeout)_ setup and teardown, but conspicuously absent is _per-worker_ setup and teardown. ## Motivation One worker's set of tests runs serially, and is ideally suited to reusing an exclusive resource like a database or redis connection. ## Example Sue has a test suite that uses a database. She can create _multiple_ databases, but there is a time cost associated with spinning one up before it can be used. From her test suite she'd like to get maximum concurrency with minimum database setup time. Currently possible approaches: 1) One database, run all the tests serially. * This is unacceptably slow. Concurrency is one of Jest's killer features and it's sad to lose it. 2) Multiple databases, created on fly at runtime, per-file. (in e.g. `beforeAll()`) * This pays the database setup cost many more times than is necessary, slowing down the test suite. 3) Multiple databases, created upfront. (e.g., make 20 databases, once, in `globalSetup`) * This requires you to choose a constant (e.g. **20**) according to how many workers you want to run. * Choose the wrong number for `-w` (or get the wrong number inferred by your CPU core count), and it will either do too much work or not have enough databases. * Also it's painful to wait on a large upfront cost when you're running,

Posted by jrr on Jul 17, 2019, 7:06 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments

pricing (Software)

Per-worker setup/teardown

jrrJul 17, 2019, 7:06 PM

## 🚀 Feature Proposal Jest provides _[once-global](https://jestjs.io/docs/en/configuration#globalsetup-string)_ setup and teardown, and _[per-file](https://jestjs.io/docs/en/api#beforeallfn-timeout)_ setup and teardown, but conspicuously absent is _per-worker_ setup and teardown. ## Motivation One worker's set of tests runs serially, and is ideally suited to reusing an exclusive resource like a database or redis connection. ## Example Sue has a test suite that uses a database. She can create _multiple_ databases, but there is a time cost associated with spinning one up before it can be used. From her test suite she'd like to get maximum concurrency with minimum database setup time. Currently possible approaches: 1) One database, run all the tests serially. * This is unacceptably slow. Concurrency is one of Jest's killer features and it's sad to lose it. 2) Multiple databases, created on fly at runtime, per-file. (in e.g. `beforeAll()`) * This pays the database setup cost many more times than is necessary, slowing down the test suite. 3) Multiple databases, created upfront. (e.g., make 20 databases, once, in `globalSetup`) * This requires you to choose a constant (e.g. **20**) according to how many workers you want to run. * Choose the wrong number for `-w` (or get the wrong number inferred by your CPU core count), and it will either do too much work or not have enough databases. * Also it's painful to wait on a large upfront cost when you're running,

Comments (0)

No comments yet. Start the discussion.

Comment on this issue