import * as assert from "assert" ; import { httpGet } from "../extension.bundle" ; import { networkTest } from "./networkTest.test" ; suite ( "HttpClient" , ( ) => { suite ( "get(string)" , ( ) => { networkTest ( "with existing site ('http://www.bing.com')" , ( ) => { return httpGet ( "http://www.bing.com" ) . then ( ( content ) => { assert ( content , "Content was undefined, null, or empty" ) ; assert ( content . includes ( "Bing" ) , "Content did not include the phrase 'Bing'" ) ; } ) ; } ) ; networkTest ( "with existing site without 'http' ('www.bing.com')" , ( ) => { return httpGet ( "www.bing.com" ) . then ( ( content ) => { assert ( content , "Content was undefined, null, or empty" ) ; assert ( content . includes ( "Bing" ) , "Content did not include the phrase 'Bing'" ) ; } ) ; } ) ; networkTest ( "with redirection ('https://storageexplorer.com') (redirection)" , ( ) => { return httpGet ( "https://storageexplorer.com" ) . then ( ( content ) => { assert ( content , "No content" ) ; assert ( content . includes ( "Azure Storage Explorer" ) , "Doesn't include 'Azure Storage Explorer'" ) ; } ) ; } ) ; networkTest ( "with non-existing site ('http://i.dont.exist.com')" , ( ) => { return httpGet ( "http://i.dont.exist.com" ) . then ( ( content ) => { assert ( false , "Expected the catch function to be called." ) ; } ) . catch ( ( reason ) => { assert ( reason ) ; if ( reason . code === 'EAI_AGAIN' ) { return ; } assert . deepStrictEqual ( reason . code , "ENOTFOUND" ) ; assert . deepStrictEqual ( reason . hostname , "i.dont.exist.com" ) ; assert . deepStrictEqual ( reason . syscall , "getaddrinfo" ) ; } ) ; } ) ; } ) ; } ) ;