Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit ce93f23

Browse files
authored
feat: add support for env vars (#14)
1 parent 03b42f6 commit ce93f23

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,32 @@ module.exports = {
235235
}
236236
```
237237

238+
### `options`
239+
240+
Options which will be passed down to the [spawn](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) of the process. For example environment variables:
241+
242+
```js
243+
// global-setup.js
244+
const { setup: setupDevServer, getServers } = require('jest-process-manager')
245+
246+
module.exports = async function globalSetup() {
247+
await setupDevServer({
248+
command: `node config/start.js --port=3000`,
249+
launchTimeout: 50000,
250+
port: 3000,
251+
options: {
252+
env: {
253+
"FOO": "bar",
254+
}
255+
}
256+
})
257+
getServers.then(servers => {
258+
// You can get to the servers and do whatever you want
259+
})
260+
// Your global setup
261+
}
262+
```
263+
238264
## Troubleshooting
239265

240266
- If using `port` makes the terminal to ask for root password although the port is valid and accessible then use `usePortAction: 'ignore'`.

src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,12 @@ function runServer(config: JestProcessManagerOptions, index: number) {
9393

9494
servers[index] = spawnd(config.command, {
9595
shell: true,
96-
env: process.env,
9796
cwd: cwd(),
9897
...config.options,
98+
env: {
99+
...process.env,
100+
...(config.options?.env ? config.options.env : {})
101+
}
99102
})
100103

101104
if (config.debug) {
@@ -222,8 +225,8 @@ async function setupJestServer(providedConfig: JestProcessManagerOptions, index:
222225
await waitOn(opts)
223226
} catch (err) {
224227
throw new JestProcessManagerError(
225-
`Server has taken more than ${launchTimeout}ms to start.`,
226-
ERROR_TIMEOUT,
228+
`Server has taken more than ${launchTimeout}ms to start.`,
229+
ERROR_TIMEOUT,
227230
)
228231
}
229232
} else {

0 commit comments

Comments
 (0)