-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: use dynamic port for web proxy tests
This changes the web proxy tests to use a dynamic, unused port instead of the default 8080 port, which could cause the tests to fail if 8080 is being used.
- Loading branch information
Showing
3 changed files
with
23 additions
and
17 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
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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import net from 'net'; | ||
|
||
/** | ||
* Discovers and returns a dynamically assigned, unused port available for testing. | ||
*/ | ||
export const getUnusedPort = async () => { | ||
return new Promise<number>((resolve, reject) => { | ||
const server = net.createServer(); | ||
server.unref(); | ||
server.on('error', reject); | ||
server.listen(0, () => { | ||
const { port } = server.address(); | ||
server.close(() => { | ||
resolve(port); | ||
}); | ||
}); | ||
}); | ||
}; |