mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-29 16:45:49 +00:00
[FIX] handle websocket errors in browsers
emit not RippledNotInitializedError if server doesn't have any completed ledgers on connect
This commit is contained in:
26
test/utils/net-utils.js
Normal file
26
test/utils/net-utils.js
Normal file
@@ -0,0 +1,26 @@
|
||||
'use strict'; // eslint-disable-line
|
||||
|
||||
const net = require('net');
|
||||
|
||||
// using a free port instead of a constant port enables parallelization
|
||||
function getFreePort() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const server = net.createServer();
|
||||
let port;
|
||||
server.on('listening', function() {
|
||||
port = server.address().port;
|
||||
server.close();
|
||||
});
|
||||
server.on('close', function() {
|
||||
resolve(port);
|
||||
});
|
||||
server.on('error', function(error) {
|
||||
reject(error);
|
||||
});
|
||||
server.listen(0);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getFreePort
|
||||
};
|
||||
Reference in New Issue
Block a user