import * as dns from "dns" ; import { Context } from "mocha" ; let internetConnected ; /**
 * Determine if the running application has internet connectivity.
 */ function hasInternetConnection ( ) { if ( internetConnected === undefined ) { internetConnected = new Promise < boolean > ( ( resolve , reject ) => { dns . lookup ( "www.microsoft.com" , ( error , address , family ) => { resolve ( ! error ) ; } ) ; } ) ; } return internetConnected ; } /**
 * A test that is dependant on internet connectivity. If the application is not currently connected
 * to the internet, then the test will be skipped.
 */ export function networkTest ( testName , testFunction ) { test ( testName , function ( this ) : Promise < void > { this . timeout ( 10000 ) ; return hasInternetConnection ( ) . then ( ( connected ) => { if ( connected ) { return testFunction ( ) ; } else { return this . skip ( ) ; } } ) ; } ) ; }