fix: filter empty entries from config --services command

This commit is contained in:
Alexander Zeitler 2021-04-11 15:59:53 +02:00
parent 51b20b43d6
commit ed91eba770
2 changed files with 5 additions and 4 deletions

View file

@ -60,6 +60,8 @@ export type TypedDockerComposeResult<T> = {
data: T
}
const nonEmptyString = (v: string) => v !== ''
/**
* Converts supplied yml files to cli arguments
* https://docs.docker.com/compose/reference/overview/#use--f-to-specify-name-and-path-of-one-or-more-compose-files
@ -329,7 +331,7 @@ export const configServices = async function (
): Promise<TypedDockerComposeResult<DockerComposeConfigServicesResult>> {
try {
const result = await execCompose('config', ['--services'], options)
const services = result.out.split('\n')
const services = result.out.split('\n').filter(nonEmptyString)
return {
...result,
data: { services }
@ -344,8 +346,7 @@ export const configVolumes = async function (
): Promise<TypedDockerComposeResult<DockerComposeConfigVolumesResult>> {
try {
const result = await execCompose('config', ['--volumes'], options)
const nonEmpty = (v: string) => v !== ''
const volumes = result.out.split('\n').filter(nonEmpty)
const volumes = result.out.split('\n').filter(nonEmptyString)
return {
...result,
data: { volumes }

View file

@ -528,7 +528,7 @@ test('config show data for docker-compose files (services)', async (): Promise<v
config: 'docker-compose-build.yml'
})
expect(std.data.services.length).toBe(6)
expect(std.data.services.length).toBe(5)
expect(std.data.services[0]).toBe('build_test_1')
expect(std.err).toBeFalsy()
})