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

fix: jest-dev-server can't detect used ports #235

Merged
merged 1 commit into from
May 1, 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
4 changes: 2 additions & 2 deletions packages/jest-dev-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ module.exports = {

### `protocol`

Type: `string`, default to `null`.
Type: `string`, (`https`, `http`, `tcp`, `socket`) default to `tcp`.

To wait for an HTTP endpoint before considering the server running, include `http` as a protocol.
To wait for an HTTP or TCP endpoint before considering the server running, include `http` or `tcp` as a protocol.
Must be used in conjunction with `port`.

```js
Expand Down
36 changes: 17 additions & 19 deletions packages/jest-dev-server/src/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const DEFAULT_CONFIG = {
launchTimeout: 5000,
host: 'localhost',
port: null,
protocol: 'http',
protocol: 'tcp',
usedPortAction: 'ask',
waitOnScheme: {},
}
Expand Down Expand Up @@ -189,28 +189,26 @@ async function setupJestServer(providedConfig, index) {
if (config.port) {
const { launchTimeout, protocol, host, port, waitOnScheme } = config

let url = ''
if (protocol === 'tcp' || protocol === 'socket') {
url = `${protocol}:${host}:${port}`
} else {
url = `${protocol}://${host}:${port}`
}
const opts = {
resources: [`${protocol}://${host}:${port}`],
resources: [url],
timeout: launchTimeout,
...waitOnScheme,
}

let timeout
await Promise.race([
new Promise((resolve, reject) => {
timeout = setTimeout(
() =>
reject(
new JestDevServerError(
`Server has taken more than ${launchTimeout}ms to start.`,
ERROR_TIMEOUT,
),
),
launchTimeout,
)
}),
waitOn(opts),
])
clearTimeout(timeout)
try {
await waitOn(opts)
} catch (err) {
throw new JestDevServerError(
`Server has taken more than ${launchTimeout}ms to start.`,
ERROR_TIMEOUT,
)
}
}
}

Expand Down