diff --git a/src/port-mapper.ts b/src/port-mapper.ts index f7c3d11f..ca036858 100644 --- a/src/port-mapper.ts +++ b/src/port-mapper.ts @@ -7,24 +7,22 @@ const mapPorts = ( const result = !ports ? [] : (() => { - return ports.split(',').map((untypedPort) => { - const exposedFragments = untypedPort.trim().split('->') + return ports.split(',').map((untypedPort) => { + const exposedFragments = untypedPort.trim().split('->') - console.log(exposedFragments) - - const [port, protocol] = - exposedFragments.length === 1 - ? exposedFragments[0].split('/') - : exposedFragments[1].split('/') - const [address, mappedPort] = - exposedFragments.length === 2 ? exposedFragments[0].split(':') : [] - return { - exposed: { port: Number(port), protocol }, - ...(address && - mappedPort && { mapped: { port: Number(mappedPort), address } }) - } - }) - })() + const [port, protocol] = + exposedFragments.length === 1 + ? exposedFragments[0].split('/') + : exposedFragments[1].split('/') + const [address, mappedPort] = + exposedFragments.length === 2 ? exposedFragments[0].split(':') : [] + return { + exposed: { port: Number(port), protocol }, + ...(address && + mappedPort && { mapped: { port: Number(mappedPort), address } }) + } + }) + })() return result } diff --git a/test/index.test.ts b/test/index.test.ts index 4ba4fc70..422123e8 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -2,7 +2,7 @@ import Docker from 'dockerode' import * as compose from '../src/index' import * as path from 'path' import { readFile } from 'fs' -import { mapPorts, mapPsOutput } from '../src/index' +import { mapPsOutput } from '../src/index' const docker = new Docker() // Docker commands, especially builds, can take some time. This makes sure that they can take the time they need. @@ -94,25 +94,21 @@ test('ensure exit code is returned correctly', async (): Promise => { }) describe('starts containers properly with --build and --timeout options', (): void => { - beforeEach( - async (): Promise => { - await compose.down({ - cwd: path.join(__dirname), - log: logOutput, - config: 'docker-compose-build.yml' - }) - } - ) + beforeEach(async (): Promise => { + await compose.down({ + cwd: path.join(__dirname), + log: logOutput, + config: 'docker-compose-build.yml' + }) + }) - afterEach( - async (): Promise => { - await compose.down({ - cwd: path.join(__dirname), - log: logOutput, - config: 'docker-compose-build.yml' - }) - } - ) + afterEach(async (): Promise => { + await compose.down({ + cwd: path.join(__dirname), + log: logOutput, + config: 'docker-compose-build.yml' + }) + }) test('ensure container gets started with --build option', async (): Promise => { await compose.upAll({ diff --git a/test/port-mapper.test.ts b/test/port-mapper.test.ts index 405c7946..a4fff45d 100644 --- a/test/port-mapper.test.ts +++ b/test/port-mapper.test.ts @@ -1,4 +1,4 @@ -import mapPorts from "../src/port-mapper"; +import mapPorts from '../src/port-mapper' test('map ports for empty string', () => { expect(mapPorts('')).toEqual([]) @@ -33,22 +33,26 @@ test('map multiple tcp ports exposed on ivp4 interfaces', () => { }) test('map multiple tcp ports exposed on ipv4 and ipv6 interfaces', () => { - expect(mapPorts('0.0.0.0:443->443/tcp,:::443->443/tcp, 0.0.0.0:80->80/tcp,:::80->80/tcp')).toEqual([ + expect( + mapPorts( + '0.0.0.0:443->443/tcp,:::443->443/tcp, 0.0.0.0:80->80/tcp,:::80->80/tcp' + ) + ).toEqual([ { exposed: { port: 443, protocol: 'tcp' }, - mapped: { address: '0.0.0.0', port: 443 }, + mapped: { address: '0.0.0.0', port: 443 } }, { exposed: { port: 443, protocol: 'tcp' }, - mapped: { address: ':::', port: 443 }, + mapped: { address: ':::', port: 443 } }, { exposed: { port: 80, protocol: 'tcp' }, - mapped: { address: '0.0.0.0', port: 80 }, + mapped: { address: '0.0.0.0', port: 80 } }, { exposed: { port: 80, protocol: 'tcp' }, - mapped: { address: ':::', port: 80 }, - }, + mapped: { address: ':::', port: 80 } + } ]) })