diff --git a/README.md b/README.md index bf98773..ee50ed4 100644 --- a/README.md +++ b/README.md @@ -235,6 +235,32 @@ module.exports = { } ``` +### `options` + +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: + +```js +// global-setup.js +const { setup: setupDevServer, getServers } = require('jest-process-manager') + +module.exports = async function globalSetup() { + await setupDevServer({ + command: `node config/start.js --port=3000`, + launchTimeout: 50000, + port: 3000, + options: { + env: { + "FOO": "bar", + } + } + }) + getServers.then(servers => { + // You can get to the servers and do whatever you want + }) + // Your global setup +} +``` + ## Troubleshooting - If using `port` makes the terminal to ask for root password although the port is valid and accessible then use `usePortAction: 'ignore'`. diff --git a/src/index.ts b/src/index.ts index 1db528a..ac7081a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -93,9 +93,12 @@ function runServer(config: JestProcessManagerOptions, index: number) { servers[index] = spawnd(config.command, { shell: true, - env: process.env, cwd: cwd(), ...config.options, + env: { + ...process.env, + ...(config.options?.env ? config.options.env : {}) + } }) if (config.debug) { @@ -222,8 +225,8 @@ async function setupJestServer(providedConfig: JestProcessManagerOptions, index: await waitOn(opts) } catch (err) { throw new JestProcessManagerError( - `Server has taken more than ${launchTimeout}ms to start.`, - ERROR_TIMEOUT, + `Server has taken more than ${launchTimeout}ms to start.`, + ERROR_TIMEOUT, ) } } else {