From 210a86151b8996a9d472ca4659dc0f5e5e2e97e5 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Tue, 23 Jun 2020 10:36:03 +0200 Subject: [PATCH 1/2] docs: add spawn options Closes #13 --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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'`. From 62dbc6b755c6d37b134ae43d658e6a17182d793d Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Wed, 24 Jun 2020 10:04:40 +0200 Subject: [PATCH 2/2] fix: environment variables --- src/index.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 {