feat: add getRandomAvailablePort function and update tests

This commit is contained in:
tone
2025-10-15 16:00:59 +08:00
parent ab288c24aa
commit 6fbba3f4c6
2 changed files with 35 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
import { isObject, isString, makeId } from "@/utils/utils"
import { getRandomAvailablePort, isObject, isString, makeId } from "@/utils/utils"
test('makeId', () => {
const id = makeId();
@@ -20,4 +20,10 @@ test('isString', () => {
expect(isString(str)).toBeTruthy();
const aNumber = 1;
expect(isString(aNumber)).toBeFalsy();
})
test('getRandomAvailablePort', async () => {
const port = await getRandomAvailablePort();
expect(port).toBeGreaterThanOrEqual(1);
expect(port).toBeLessThanOrEqual(65535);
})