Skip to content

Commit 2519e76

Browse files
committed
Add documentation
1 parent e81f99a commit 2519e76

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
11
# @ava/get-port
22

33
Experimental AVA plugin which works like [`get-port`](https://github.com/sindresorhus/get-port), but ensures the port is locked across all test files.
4+
5+
Install this as a development dependency alongside AVA itself:
6+
7+
```console
8+
npm install --save-dev @ava/get-port
9+
```
10+
11+
Then make sure you've enabled the shared workers experiment:
12+
13+
`ava.config.js`:
14+
15+
```js
16+
export default {
17+
nonSemVerExperiments: {
18+
sharedWorkers: true
19+
}
20+
};
21+
```
22+
23+
## Usage
24+
25+
```ts
26+
const {default: getPort} = require('@ava/get-port');
27+
28+
test.before('get port', async t => {
29+
t.context.port = await getPort();
30+
});
31+
```
32+
33+
`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.

0 commit comments

Comments
 (0)