UNPKG

@applitools/execution-grid-tunnel

Version:

Allows user to run tests with exection-grid and navigate to private hosts and ips

34 lines (28 loc) 1 kB
const net = require('net') const tls = require('tls') module.exports = {connectivityTest} function connectivityTest({host, port = 80, protocol = 'tcp', timeout = 10000}) { return new Promise((resolve) => { const startTime = Date.now() const remoteConnection = protocol == 'tcp' ? net.connect({port, host, timeout}) : tls.connect(port, host, {timeout}) remoteConnection.once('connect', () => { remoteConnection.end() resolve({success: true, timeTaken: Date.now() - startTime}) }) remoteConnection.once('error', (error) => { remoteConnection.end() resolve({ success: false, timeTaken: Date.now() - startTime, error: error.code, errorMessage: error.stack || error.message, }) }) remoteConnection.once('timeout', () => { remoteConnection.end() resolve({success: false, timeTaken: Date.now() - startTime, error: 'CONNECTION_TIMEOUT'}) }) // remoteConnection.setTimeout(timeout) }) }