Skip to content

Commit

Permalink
feat: add waitOnScheme options (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyuhen authored and gregberge committed Apr 29, 2019
1 parent a415654 commit f772d74
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
28 changes: 28 additions & 0 deletions packages/jest-dev-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,34 @@ module.exports = {
}
```

### `waitOnScheme`

`jest-dev-server` use the [`wait-on`](https://www.npmjs.com/package/wait-on) npm package to wait for resources to become available before calling callback.

Type: `object`, default to `{}`.

- `delay`: optional initial delay in ms, default 0
- `interval`: optional poll resource interval in ms, default 250ms
- `log`: optional flag which outputs to stdout, remaining resources waited on and when complete or errored
- `reverse`: optional flag to reverse operation so checks are for resources being NOT available, default false
- `timeout`: optional timeout in ms, default Infinity. Aborts with error
- `tcpTimeout`: optional tcp timeout in ms, default 300ms
- `verbose`: optional flag which outputs debug output, default false
- `window`: optional stabilization time in ms, default 750ms. Waits this amount of time for file sizes to stabilize or other resource availability to remain unchanged

**Note:** http(s) specific options, see https://github.com/request/request#readme for specific details

```js
module.exports = {
command: 'npm run start --port 3000',
port: 3000,
usedPortAction: 'kill',
waitOnScheme: {
delay: 1000,
},
}
```

## Troubleshooting

- If using `port` makes the terminal to ask for root password although the port is valid and accessible then use `usePortAction: 'ignore'`.
Expand Down
4 changes: 3 additions & 1 deletion packages/jest-dev-server/src/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const DEFAULT_CONFIG = {
port: null,
protocol: 'http',
usedPortAction: 'ask',
waitOnScheme: {},
}

const pTreeKill = promisify(treeKill)
Expand Down Expand Up @@ -186,10 +187,11 @@ async function setupJestServer(providedConfig, index) {
}

if (config.port) {
const { launchTimeout, protocol, host, port } = config
const { launchTimeout, protocol, host, port, waitOnScheme } = config

const opts = {
resources: [`${protocol}://${host}:${port}`],
...waitOnScheme,
}

let timeout
Expand Down

0 comments on commit f772d74

Please sign in to comment.