import http from 'http' ; import fetch from 'node-fetch' ; import { getHostAddress , getServiceAddress } from 'dockest/test-helper' ; const TARGET_HOST = getServiceAddress ( 'docker_in_docker_website' , 9000 ) ; const HOSTNAME = getHostAddress ( ) ; const PORT = 8080 ; let server ; afterEach ( async ( ) => { if ( server ) { await new Promise ( ( resolve , reject ) => { server . close ( err => { if ( err ) { reject ( err ) ; return ; } resolve ( ) ; } ) ; } ) ; } } ) ; test ( 'can send a request to the container and it can send a request to us' , async ( done ) => { await new Promise ( resolve => { server = http . createServer ( ( _req , res ) => { res . write ( 'Hello World!' ) ; res . end ( ) ; done ( ) ; } ) . listen ( PORT , ( ) => { console . log ( `Serving on http://${ HOSTNAME }:${ PORT }` ) ; resolve ( ) ; } ) ; } ) ; const res = await fetch ( `http://${ TARGET_HOST }` , { method : 'post' , body : `http://${ HOSTNAME }:${ PORT }` , } ) . then ( res => res . text ( ) ) ; expect ( res ) . toEqual ( 'OK.' ) ; } ) ;