Skip to content

Commit

Permalink
Remove the get-port package and implement the functionality directly
Browse files Browse the repository at this point in the history
  • Loading branch information
MylesBorins committed Mar 18, 2024
1 parent 5f83b66 commit e4fd294
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
19 changes: 0 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
},
"devDependencies": {
"eslint": "^8.36.0",
"get-port": "^6.1.2",
"rollup": "^4.9.5",
"tap": "^18.4.2"
}
Expand Down
1 change: 0 additions & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ function walkTest(config) {
},
external: [
'node:dgram',
'get-port',
'node-osc',
'osc-min',
'tap',
Expand Down
29 changes: 25 additions & 4 deletions test/util.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
async function bootstrap(t) {
const {default: getPorts, portNumbers} = await import('get-port');
const port = await getPorts({
port: portNumbers(3000, 3500)
import { createSocket } from 'node:dgram';

// A custom getPort function that returns a promise that resolves with a random port within a range that is available
function getPort(min = 3000, max = 3500) {
return new Promise((resolve) => {
// Create a socket
const socket = createSocket('udp4');
// Generate a random port within the range
const port = Math.floor(Math.random() * (max - min + 1)) + min;
// Try to bind the socket to the port
socket.bind(port, (err) => {
if (err) {
// If there is an error, try again with a different port
socket.close();
resolve(getPort(min, max));
} else {
// If successful, close the socket and resolve the promise with the port
socket.close();
resolve(port);
}
});
});
}

async function bootstrap(t) {
const port = await getPort(3000, 3500);
t.context = {
port
};
Expand Down

0 comments on commit e4fd294

Please sign in to comment.