-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e81f99a
commit 2519e76
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,33 @@ | ||
# @ava/get-port | ||
|
||
Experimental AVA plugin which works like [`get-port`](https://github.com/sindresorhus/get-port), but ensures the port is locked across all test files. | ||
|
||
Install this as a development dependency alongside AVA itself: | ||
|
||
```console | ||
npm install --save-dev @ava/get-port | ||
``` | ||
|
||
Then make sure you've enabled the shared workers experiment: | ||
|
||
`ava.config.js`: | ||
|
||
```js | ||
export default { | ||
nonSemVerExperiments: { | ||
sharedWorkers: true | ||
} | ||
}; | ||
``` | ||
|
||
## Usage | ||
|
||
```ts | ||
const {default: getPort} = require('@ava/get-port'); | ||
|
||
test.before('get port', async t => { | ||
t.context.port = await getPort(); | ||
}); | ||
``` | ||
|
||
`getPort()` reserves a port, such that no other concurrently executing test file also using `getPort()` will select that same port. To ensure the port is available it then (briefly) listens. You can [pass options used when listening](https://nodejs.org/docs/latest/api/net.html#net_server_listen_options_callback). You can't pass `port` though. |