https://github.com/filipoliko/jest-worker-threads-share-env
https://github.com/filipoliko/jest-worker-threads-share-env
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/filipoliko/jest-worker-threads-share-env
- Owner: Filipoliko
- Created: 2021-04-09T13:39:41.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-12T07:12:46.000Z (about 5 years ago)
- Last Synced: 2025-02-10T13:22:16.522Z (over 1 year ago)
- Language: JavaScript
- Size: 46.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Jest Worker Threads Share Env Test
This repo shows, that `SHARE_ENV` in `worker_threads` does not work share the environment variables when running tests in Jest environment.
## Installation
```bash
npm install
```
## Run Test
Scenario:
- Init worker (`worker.js`) with option `env: SHARE_ENV` ([docs](https://nodejs.org/docs/latest-v14.x/api/worker_threads.html#worker_threads_worker_share_env))
- Worker sets environment variable `JEST_SHARE_ENV` to `foo`
Now we expect, that thanks to using `SHARE_ENV`, the environment variable would also propagate to master process. This does not work when running tests in Jest environment.
To run both, Node and Jest version of the test, use the following command:
```bash
npm test
```
To run the Node version only:
```bash
node assert.js
```
To run the Jest version only:
```bash
npx jest
```