Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add waitOnScheme options #232

Merged
merged 2 commits into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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